﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;

namespace TestDxfDocument
{
    class ToolHoldersForIndexableInserts
    {
        public static void ToolHolderForLongitudinalAndTransversalTurning(Dictionary<string, Object> data)  //5.径向和横向车削刀柄
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
            //作图
            //参数
            string path = Convert.ToString(data["path"]);
            double slf = Convert.ToDouble(data["lf"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0)
            {
                if (slf < 67)
                {
                    scale = 4.0;
                }
                else if (slf < 90)
                {
                    scale = 3.0;
                }
                else if (slf < 134)
                {
                    scale = 2.0;
                }
                else if (slf < 178)
                {
                    scale = 1.5;
                }
                else if (slf < 268)
                {
                    scale = 1.0;
                }
                else if (slf < 357)
                {
                    scale = 0.75;
                }
                else
                {
                    scale = 0.5;
                }
            }
            double pi = Math.PI;
            string ceatc = Convert.ToString(data["ceatc"]);
            string sx = Convert.ToString(data["sx"]);
            string thsc = Convert.ToString(data["thsc"]);
            string sc = Convert.ToString(data["sc"]);
            double lf = Convert.ToDouble(data["lf"]) * scale;
            double lh = Convert.ToDouble(data["lh"]) * scale;
            double b = Convert.ToDouble(data["b"]) * scale;
            double h = Convert.ToDouble(data["h"]) * scale;
            double wf = Convert.ToDouble(data["wf"]) * scale;
            double dcon = Convert.ToDouble(data["dcon"]) * scale;
            double ic = Convert.ToDouble(data["ic"]) * scale;
            double ecd = Convert.ToDouble(data["ecd"]) * scale;
            //double bdred = 5 * scale;
            double epsr = Convert.ToDouble(data["epsr"]) * pi / 180;
            double kapr = Convert.ToDouble(data["kapr"]) * pi / 180;
            double hea = Convert.ToDouble(data["hea"]) * pi / 180;
            double eca = Convert.ToDouble(data["eca"]) * pi / 180;
            //double ldred = 35 * scale;
            double s = Convert.ToDouble(data["s"]) * scale;
            double an = Convert.ToDouble(data["an"]) * pi / 180;
            double isframe = Convert.ToDouble(data["isframe"]);
            //坐标
            //主视图
            if (sx == "02")//车刀
            {
                if (thsc == "O")//偏头
                {
                    if (ceatc == "E")//端切
                    {
                        if (sc == "T")//三角形刀片
                        {
                            double l = ic * (1 + Math.Cos(pi / 3)) / 2 / Math.Cos(pi / 3)/ Math.Sin(pi / 3);
                            Vector2 v1 = new Vector2(0, 0);
                            Vector2 v2 = new Vector2(b, 0);
                            Vector2 v3 = new Vector2(v2.X, -lf-l*Math.Cos(kapr)+lh);
                            Vector2 v4 = new Vector2(0, v3.Y);
                            Vector2 v7 = new Vector2(wf - l * Math.Sin(kapr), -lf - l * Math.Cos(kapr));
                            Vector2 v6 = new Vector2(ecd, s*Math.Tan(an)/Math.Sin(pi/6)*Math.Sin(2*pi/3-kapr)+v7.Y);
                            Vector2 v5 = new Vector2(0, v6.Y + ecd / Math.Tan(eca));
                            Vector2 v9 = new Vector2(wf, -lf);
                            Vector2 v8 = new Vector2(v7.X - l * Math.Cos(kapr + pi / 6), v7.Y + l * Math.Sin(kapr + pi / 6));
                            Vector2 v10 = new Vector2(v9.X- s * Math.Tan(an) / Math.Sin(pi / 6) * Math.Cos(pi / 3 - kapr), v9.Y+ s * Math.Tan(an) / Math.Sin(pi / 6) * Math.Cos(pi / 3 - kapr) * Math.Tan(kapr-pi / 6));
                            Vector2 v11 = new Vector2(v2.X, -h - 5 * scale);
                            Vector2 v12 = new Vector2(0, v11.Y);
                            Vector2 v13 = new Vector2(0, -5*scale);
                            Vector2 v14 = new Vector2(v11.X, v13.Y);
                            Vector2 v15 = new Vector2(v9.X, v7.Y);
                            Vector2 v16 = new Vector2(v5.X, v6.Y);
                            Vector2 v17 = new Vector2(v7.X - (v6.Y - v7.Y) * Math.Tan(pi / 3 - kapr), v6.Y);
                            Vector2 v18 = new Vector2(v10.X, v3.Y - (v10.X-v3.X) / Math.Tan(hea));
                            //线段
                            //主视图
                            Vector2[] Line1 = { v1, v2 };
                            fun.drawBLine(dxf, Line1, 0.3, contour);
                            Vector2[] Line2 = { v2, v3 };
                            fun.drawBLine(dxf, Line2, 0.3, contour);
                            Vector2[] Line19 = { v3, v18 };
                            fun.drawBLine(dxf, Line19, 0.3, contour);
                            Vector2[] Line20 = { v18, v10 };
                            fun.drawBLine(dxf, Line20, 0.3, contour);
                            if (ecd != 0)
                            {
                                Vector2[] Line3 = { v1, v5 };
                                fun.drawBLine(dxf, Line3, 0.3, contour);
                                Vector2[] Line4 = { v5, v6 };
                                fun.drawBLine(dxf, Line4, 0.3, contour);
                                Vector2[] Line5 = { v6, v17 };
                                fun.drawBLine(dxf, Line5, 0.3, contour);
                            }
                            if (ecd == 0)
                            {
                                Vector2[] Line3 = { v1, v16 };
                                fun.drawBLine(dxf, Line3, 0.3, contour);
                                Vector2[] Line5 = { v16, v17 };
                                fun.drawBLine(dxf, Line5, 0.3, contour);
                            }
                            Vector2[] Line6 = { v7, v9 };
                            fun.drawBLine(dxf, Line6, 0.3, contour);
                            Vector2[] Line7 = { v7, v8 };
                            fun.drawBLine(dxf, Line7, 0.3, contour);
                            Vector2[] Line8 = { v8, v9 };
                            fun.drawBLine(dxf, Line8, 0.3, contour);
                            if (lh != 0)
                            {
                                Vector2[] Line9 = { v3, v4 };
                                fun.drawBLine(dxf, Line9, 0.3, contour);
                            }
                            Vector2[] Line10 = { v11, v12 };
                            fun.drawPlinetype(dxf, Line10, 0.15, refin, Linetype.DashDot);
                            Vector2[] Line11 = { v13, v14 };
                            fun.drawPlinetype(dxf, Line11, 0.15, refin, Linetype.DashDot);
                            Line Line12 = new Line(v11, v12);
                            Line Line13 = new Line(v13, v14);
                            Line Line14 = new Line(v5, v16);
                            Line Line15 = new Line(v9, v15);
                            Line14.Layer = dimensioning;
                            Line15.Layer = dimensioning;
                            dxf.AddEntity(Line14);
                            dxf.AddEntity(Line15);
                            Line Line16 = new Line(v5, v6);
                            Line Line17 = new Line(v9, v7);
                            Line Line18 = new Line(v9, v8);
                            //填充
                            LwPolyline hatchpoly3 = new LwPolyline();
                            hatchpoly3.Vertexes.Add(new LwPolylineVertex(v11));
                            hatchpoly3.Vertexes.Add(new LwPolylineVertex(v12));
                            hatchpoly3.Vertexes.Add(new LwPolylineVertex(v13));
                            hatchpoly3.Vertexes.Add(new LwPolylineVertex(v14));
                            hatchpoly3.IsClosed = true;
                            String[] htype3 = new String[100];
                            Line[] hline3 = new Line[100];
                            int hnumst3 = hatchpoly3.Explode().Count;  //记录爆炸后，线段有多少
                            for (int i = 0; i < hnumst3; i++)
                            {
                                htype3[i] = hatchpoly3.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                                if (htype3[i] == "Line")
                                {
                                    hline3[i] = (Line)hatchpoly3.Explode()[i];
                                }
                            }
                            fun.hatchsubofline(dxf, htype3, hnumst3, 45, 5, hline3, hatching);
                            //标注样式
                            //箭头样式
                            DimensionStyle dimensionStyle = fun.CreateDimStyle();
                            dimensionStyle.ArrowSize = 0.2;
                            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                            //文本样式
                            dimensionStyle.TextHeight = 1.0;
                            double offset = 10;
                            //线段尺寸标注
                            //尺寸1
                            if (lh != 0)
                            {
                                LinearDimension dim1 = new LinearDimension(new Line(v4, v7), -offset - v7.X / 2, 270, dimensionStyle);
                                dim1.UserText = "LH = " + Math.Round(lh / scale, 2);
                                dxf.AddEntity(dim1);
                            }
                            //尺寸2
                            LinearDimension dim2 = new LinearDimension(new Line(v4, v9), -offset*4-(v4.Y+v9.Y)/2+v7.Y, 0, dimensionStyle);
                            dim2.UserText = "WF = " + Math.Round(wf / scale, 2);
                            dxf.AddEntity(dim2);
                            //尺寸3
                            LinearDimension dim3 = new LinearDimension(new Line(v2, v9), offset+(v9.X-v2.X)/2, 270, dimensionStyle);
                            dim3.UserText = "LF = " + Math.Round(lf / scale, 2);
                            dxf.AddEntity(dim3);
                            //尺寸4
                            LinearDimension dim4 = new LinearDimension(new Line(v2, v7), offset*2 + v9.X-(v2.X+v7.X)/2, 270, dimensionStyle);
                            dim4.UserText = "OAL = " + Math.Round(-v7.Y / scale, 2);
                            dxf.AddEntity(dim4);
                            //尺寸5
                            if (ecd != 0)
                            {
                                LinearDimension dim5 = new LinearDimension(new Line(v16, v6), -offset*3, 0, dimensionStyle);
                                dim5.UserText = "ECD = " + Math.Round(ecd / scale, 2);
                                dxf.AddEntity(dim5);
                            }
                            //尺寸6
                            LinearDimension dim6 = new LinearDimension(new Line(v1, v2), offset, 0, dimensionStyle);
                            dim6.UserText = "B = " + Math.Round(b / scale, 2);
                            dxf.AddEntity(dim6);
                            //尺寸11
                            Angular2LineDimension angdim11 = new Angular2LineDimension(Line15, Line17, offset*2, dimensionStyle);
                            angdim11.UserText = "KAPR = " + Math.Round(kapr / pi * 180, 2) + "°";
                            dxf.AddEntity(angdim11);
                            //尺寸10
                            if (ecd != 0)
                            {
                                Angular2LineDimension angdim10 = new Angular2LineDimension(Line16, Line14, offset, dimensionStyle);
                                angdim10.UserText = "ECA = " + Math.Round(eca / pi * 180, 2) + "°";
                                dxf.AddEntity(angdim10);
                            }
                            //尺寸13
                            Angular2LineDimension angdim13 = new Angular2LineDimension(Line18, Line17, l/2, dimensionStyle);
                            angdim13.UserText = "EPSR = " + Math.Round(epsr / pi * 180, 2) + "°";
                            dxf.AddEntity(angdim13);
                            //尺寸12
                            LinearDimension dim12 = new LinearDimension(new Line(v12, v13), -offset, 270, dimensionStyle);
                            dim12.UserText = "H = " + Math.Round(h / scale, 2);
                            dxf.AddEntity(dim12);
                        }
                        if (sc == "R")//圆形刀片
                        {
                            double icn = ic - s * Math.Tan(an) * 2;
                            Vector2 v1 = new Vector2(0, 0);
                            Vector2 v2 = new Vector2(b, 0);
                            Vector2 v3 = new Vector2(v2.X, -lf + lh);
                            Vector2 v4 = new Vector2(0, v3.Y);
                            Vector2 v7 = new Vector2(wf - ic/2, -lf + ic/2);
                            double l = Math.Sqrt((v3.Y - v7.Y) * (v3.Y - v7.Y) + (v7.X - v3.X) * (v7.X - v3.X) - icn * icn/4);
                            Vector2 v15 = new Vector2((v3.X * icn/2 / l-v7.Y + v7.X * l / (icn/2)+v3.Y) / (icn/2 / l + l / icn*2), (v7.X - v3.X + v3.Y * icn/2 / l + v7.Y * l / icn*2) / (icn/2 / l + l / icn*2));
                            double k1 = (v3.Y - v15.Y) / (v3.X - v15.X);
                            double b1 = v3.Y - v3.X * (v3.Y - v15.Y) / (v3.X - v15.X);
                            Vector2 v8 = new Vector2(-(k1 * b1 - v7.X - v7.Y * k1 + Math.Sqrt((k1 * b1 - v7.X - v7.Y * k1) * (k1 * b1 - v7.X - v7.Y * k1) - (1 + k1 * k1) * (v7.X * v7.X + b1 * b1 + v7.Y * v7.Y - 2 * v7.Y * b1 - ic * ic / 4))) / (1 + k1 * k1), -k1 * (k1 * b1 - v7.X - v7.Y * k1 + Math.Sqrt((k1 * b1 - v7.X - v7.Y * k1) * (k1 * b1 - v7.X - v7.Y * k1) - (1 + k1 * k1) * (v7.X * v7.X + b1 * b1 + v7.Y * v7.Y - 2 * v7.Y * b1 - ic * ic / 4))) / (1 + k1 * k1) + b1);
                            Vector2 v14 = new Vector2(v7.X - icn/2 * Math.Cos(eca), v7.Y - icn/2 * Math.Sin(eca));
                            Vector2 v5 = new Vector2(0, v14.Y + v14.X / Math.Tan(eca));
                            double k2 = (v5.Y - v14.Y) / (v5.X - v14.X);
                            double b2 = v5.Y - v5.X * (v5.Y - v14.Y) / (v5.X - v14.X);
                            Vector2 v6 = new Vector2(-(k2 * b2 - v7.X - v7.Y * k2 + Math.Sqrt((k2 * b2 - v7.X - v7.Y * k2) * (k2 * b2 - v7.X - v7.Y * k2) - (1 + k2 * k2) * (v7.X * v7.X + b2 * b2 + v7.Y * v7.Y - 2 * v7.Y * b2 - ic * ic / 4))) / (1 + k2 * k2), -k2 * (k2 * b2 - v7.X - v7.Y * k2 + Math.Sqrt((k2 * b2 - v7.X - v7.Y * k2) * (k2 * b2 - v7.X - v7.Y * k2) - (1 + k2 * k2) * (v7.X * v7.X + b2 * b2 + v7.Y * v7.Y - 2 * v7.Y * b2 - ic * ic / 4))) / (1 + k2 * k2) + b2);
                            Vector2 v9 = new Vector2(v2.X, -h - 5 * scale);
                            Vector2 v10 = new Vector2(0, v9.Y);
                            Vector2 v11 = new Vector2(0, -5 * scale);
                            Vector2 v12 = new Vector2(v9.X, v11.Y);
                            Vector2 v13 = new Vector2(v5.X, v6.Y);
                            //线段
                            //主视图
                            Vector2[] Line1 = { v1, v2 };
                            fun.drawBLine(dxf, Line1, 0.3, contour);
                            Vector2[] Line2 = { v2, v3 };
                            fun.drawBLine(dxf, Line2, 0.3, contour);
                            Vector2[] Line19 = { v3, v8 };
                            fun.drawBLine(dxf, Line19, 0.3, contour);
                            Vector2[] Line20 = { v5, v6 };
                            fun.drawBLine(dxf, Line20, 0.3, contour);
                            Vector2[] Line3 = { v1, v5 };
                            fun.drawBLine(dxf, Line3, 0.3, contour);
                            fun.drawcircle(dxf, v7, ic / 2, 0.3, contour);
                            if (lh != 0)
                            {
                                Vector2[] Line9 = { v3, v4 };
                                fun.drawBLine(dxf, Line9, 0.3, contour);
                            }
                            Vector2[] Line10 = { v11, v12 };
                            fun.drawPlinetype(dxf, Line10, 0.15, refin, Linetype.DashDot);
                            Vector2[] Line11 = { v9, v10 };
                            fun.drawPlinetype(dxf, Line11, 0.15, refin, Linetype.DashDot);
                            Line Line12 = new Line(v11, v12);
                            Line Line13 = new Line(v9, v10);
                            Line Line14 = new Line(v5, v13);
                            Line14.Layer = dimensioning;
                            dxf.AddEntity(Line14);
                            Line Line16 = new Line(v5, v6);
                            Circle circle15 = new Circle(v7, ic / 2);
                            //填充
                            LwPolyline hatchpoly3 = new LwPolyline();
                            hatchpoly3.Vertexes.Add(new LwPolylineVertex(v11));
                            hatchpoly3.Vertexes.Add(new LwPolylineVertex(v12));
                            hatchpoly3.Vertexes.Add(new LwPolylineVertex(v9));
                            hatchpoly3.Vertexes.Add(new LwPolylineVertex(v10));
                            hatchpoly3.IsClosed = true;
                            String[] htype3 = new String[100];
                            Line[] hline3 = new Line[100];
                            int hnumst3 = hatchpoly3.Explode().Count;  //记录爆炸后，线段有多少
                            for (int i = 0; i < hnumst3; i++)
                            {
                                htype3[i] = hatchpoly3.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                                if (htype3[i] == "Line")
                                {
                                    hline3[i] = (Line)hatchpoly3.Explode()[i];
                                }
                            }
                            fun.hatchsubofline(dxf, htype3, hnumst3, 45, 5, hline3, hatching);
                            //标注样式
                            //箭头样式
                            DimensionStyle dimensionStyle = fun.CreateDimStyle();
                            dimensionStyle.ArrowSize = 0.2;
                            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                            //文本样式
                            dimensionStyle.TextHeight = 1.0;
                            double offset = 10;
                            //线段尺寸标注
                            //尺寸1
                            if (lh != 0)
                            {
                                LinearDimension dim1 = new LinearDimension(new Line(v4, new Vector2(v7.X,v7.Y-ic/2)), -offset - v7.X / 2, 270, dimensionStyle);
                                dim1.UserText = "LH = " + Math.Round(lh / scale, 2);
                                dxf.AddEntity(dim1);
                            }
                            //尺寸2
                            LinearDimension dim2 = new LinearDimension(new Line(v5, new Vector2(v7.X+ic/2,v7.Y)), -offset*4 - (v5.Y + v7.Y) / 2 + v7.Y-ic/2, 0, dimensionStyle);
                            dim2.UserText = "WF = " + Math.Round(wf / scale, 2);
                            dxf.AddEntity(dim2);
                            //尺寸3
                            LinearDimension dim3 = new LinearDimension(new Line(v2, new Vector2(v7.X,v7.Y-ic/2)), offset + v7.X+ic/2-(v7.X + v2.X) / 2, 270, dimensionStyle);
                            dim3.UserText = "LF = " + Math.Round(lf / scale, 2);
                            dxf.AddEntity(dim3);
                            //尺寸6
                            LinearDimension dim6 = new LinearDimension(new Line(v1, v2), offset, 0, dimensionStyle);
                            dim6.UserText = "B = " + Math.Round(b / scale, 2);
                            dxf.AddEntity(dim6);
                            //尺寸10
                            Angular2LineDimension angdim10 = new Angular2LineDimension(Line16, Line14, offset, dimensionStyle);
                            angdim10.UserText = "ECA = " + Math.Round(eca / pi * 180, 2) + "°";
                            dxf.AddEntity(angdim10);
                            //尺寸11
                            DiametricDimension diadim11 = new DiametricDimension(circle15, 135, offset, dimensionStyle);
                            diadim11.UserText = "IC = φ" + Math.Round(ic / scale, 2);
                            dxf.AddEntity(diadim11);
                            //尺寸12
                            LinearDimension dim12 = new LinearDimension(new Line(v10, v11), -offset, 270, dimensionStyle);
                            dim12.UserText = "H = " + Math.Round(h / scale, 2);
                            dxf.AddEntity(dim12);
                        }
                        else//菱形刀片
                        {
                            /*double l = ic * (1 + Math.Cos(pi / 3)) / 2 / Math.Cos(pi / 3) / Math.Sin(pi / 3);
                            Vector2 v1 = new Vector2(0, 0);
                            Vector2 v2 = new Vector2(b, 0);
                            Vector2 v3 = new Vector2(v2.X, -lf + lh);
                            Vector2 v4 = new Vector2(0, v3.Y);
                            Vector2 v5 = new Vector2(0, -lf + ecd / Math.Tan(eca));
                            Vector2 v6 = new Vector2(ecd, -lf - l * Math.Cos(kapr));
                            Vector2 v7 = new Vector2(wf - l * Math.Sin(kapr), v6.Y);
                            Vector2 v9 = new Vector2(wf, -lf);
                            Vector2 v8 = new Vector2(v7.X - l * Math.Cos(kapr + pi / 6), v7.Y + l * Math.Sin(kapr + pi / 6));
                            Vector2 v10 = new Vector2(b, v9.Y + (wf - b) * Math.Tan(kapr - pi / 6));
                            Vector2 v11 = new Vector2(v10.X, -h - 5 * scale);
                            Vector2 v12 = new Vector2(0, v11.Y);
                            Vector2 v13 = new Vector2(0, -5 * scale);
                            Vector2 v14 = new Vector2(v11.X, v13.Y);
                            Vector2 v15 = new Vector2(v9.X, v7.Y);
                            Vector2 v16 = new Vector2(v5.X, v6.Y);
                            //线段
                            //主视图
                            Vector2[] Line1 = { v1, v2 };
                            fun.drawBLine(dxf, Line1, 0.3, contour);
                            Vector2[] Line2 = { v2, v10 };
                            fun.drawBLine(dxf, Line2, 0.3, contour);
                            if (ecd != 0)
                            {
                                Vector2[] Line3 = { v1, v5 };
                                fun.drawBLine(dxf, Line3, 0.3, contour);
                                Vector2[] Line4 = { v5, v6 };
                                fun.drawBLine(dxf, Line4, 0.3, contour);
                                Vector2[] Line5 = { v6, v7 };
                                fun.drawBLine(dxf, Line5, 0.3, contour);
                            }
                            if (ecd == 0)
                            {
                                Vector2[] Line3 = { v1, v16 };
                                fun.drawBLine(dxf, Line3, 0.3, contour);
                                Vector2[] Line5 = { v16, v7 };
                                fun.drawBLine(dxf, Line5, 0.3, contour);
                            }
                            Vector2[] Line6 = { v7, v9 };
                            fun.drawBLine(dxf, Line6, 0.3, contour);
                            Vector2[] Line7 = { v7, v8 };
                            fun.drawBLine(dxf, Line7, 0.3, contour);
                            Vector2[] Line8 = { v8, v9 };
                            fun.drawBLine(dxf, Line8, 0.3, contour);
                            if (lh != 0)
                            {
                                Vector2[] Line9 = { v3, v4 };
                                fun.drawBLine(dxf, Line9, 0.3, contour);
                            }
                            Vector2[] Line10 = { v11, v12 };
                            fun.drawPlinetype(dxf, Line10, refin, Linetype.DashDot);
                            Vector2[] Line11 = { v13, v14 };
                            fun.drawPlinetype(dxf, Line11, refin, Linetype.DashDot);
                            Line Line12 = new Line(v11, v12);
                            Line Line13 = new Line(v13, v14);
                            Line Line14 = new Line(v5, v16);
                            Line Line15 = new Line(v9, v15);
                            Line14.Layer = dimensioning;
                            Line15.Layer = dimensioning;
                            dxf.AddEntity(Line14);
                            dxf.AddEntity(Line15);
                            Line Line16 = new Line(v5, v6);
                            Line Line17 = new Line(v9, v7);
                            Line Line18 = new Line(v9, v8);
                            //填充
                            LwPolyline hatchpoly3 = new LwPolyline();
                            hatchpoly3.Vertexes.Add(new LwPolylineVertex(v11));
                            hatchpoly3.Vertexes.Add(new LwPolylineVertex(v12));
                            hatchpoly3.Vertexes.Add(new LwPolylineVertex(v13));
                            hatchpoly3.Vertexes.Add(new LwPolylineVertex(v14));
                            hatchpoly3.IsClosed = true;
                            String[] htype3 = new String[100];
                            Line[] hline3 = new Line[100];
                            int hnumst3 = hatchpoly3.Explode().Count;  //记录爆炸后，线段有多少
                            for (int i = 0; i < hnumst3; i++)
                            {
                                htype3[i] = hatchpoly3.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                                if (htype3[i] == "Line")
                                {
                                    hline3[i] = (Line)hatchpoly3.Explode()[i];
                                }
                            }
                            fun.hatchsubofline(dxf, htype3, hnumst3, 45, 5, hline3, hatching);
                            //标注样式
                            //箭头样式
                            DimensionStyle dimensionStyle = fun.CreateDimStyle();
                            dimensionStyle.ArrowSize = 0.2;
                            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                            //文本样式
                            dimensionStyle.TextHeight = 1.0;
                            double offset = 10;
                            //线段尺寸标注
                            //尺寸1
                            if (lh != 0)
                            {
                                LinearDimension dim1 = new LinearDimension(new Line(v4, v7), -offset - v7.X / 2, 270, dimensionStyle);
                                dim1.UserText = "LH = " + Math.Round(lh / scale, 2);
                                dxf.AddEntity(dim1);
                            }
                            //尺寸2
                            LinearDimension dim2 = new LinearDimension(new Line(v4, v9), -offset * 2 - (v4.Y + v9.Y) / 2 + v7.Y, 0, dimensionStyle);
                            dim2.UserText = "WF = " + Math.Round(wf / scale, 2);
                            dxf.AddEntity(dim2);
                            //尺寸3
                            LinearDimension dim3 = new LinearDimension(new Line(v2, v9), offset + (v9.X - v2.X) / 2, 270, dimensionStyle);
                            dim3.UserText = "LF = " + Math.Round(lf / scale, 2);
                            dxf.AddEntity(dim3);
                            //尺寸4
                            LinearDimension dim4 = new LinearDimension(new Line(v2, v7), offset * 2 + v9.X - (v2.X + v7.X) / 2, 270, dimensionStyle);
                            dim4.UserText = "OAL = " + Math.Round(-v7.Y / scale, 2);
                            dxf.AddEntity(dim4);
                            //尺寸5
                            if (ecd != 0)
                            {
                                LinearDimension dim5 = new LinearDimension(new Line(v16, v6), -offset, 0, dimensionStyle);
                                dim5.UserText = "ECD = " + Math.Round(ecd / scale, 2);
                                dxf.AddEntity(dim5);
                            }
                            //尺寸6
                            LinearDimension dim6 = new LinearDimension(new Line(v1, v2), offset, 0, dimensionStyle);
                            dim6.UserText = "B = " + Math.Round(b / scale, 2);
                            dxf.AddEntity(dim6);
                            //尺寸11
                            Angular2LineDimension angdim11 = new Angular2LineDimension(Line15, Line17, offset * 2, dimensionStyle);
                            angdim11.UserText = "KAPR = " + Math.Round(kapr / pi * 180, 2) + "°";
                            dxf.AddEntity(angdim11);
                            //尺寸10
                            if (ecd != 0)
                            {
                                Angular2LineDimension angdim10 = new Angular2LineDimension(Line16, Line14, offset, dimensionStyle);
                                angdim10.UserText = "ECA = " + Math.Round(eca / pi * 180, 2) + "°";
                                dxf.AddEntity(angdim10);
                            }
                            //尺寸13
                            Angular2LineDimension angdim13 = new Angular2LineDimension(Line18, Line17, l / 2, dimensionStyle);
                            angdim13.UserText = "EPSR = " + Math.Round(epsr / pi * 180, 2) + "°";
                            dxf.AddEntity(angdim13);
                            //尺寸12
                            LinearDimension dim12 = new LinearDimension(new Line(v12, v13), -offset, 270, dimensionStyle);
                            dim12.UserText = "H = " + Math.Round(h / scale, 2);
                            dxf.AddEntity(dim12);*/
                        }
                    }
                    if (ceatc == "S")//侧切
                    {
                        if (sc=="T")//三角形刀片
                        {

                        }
                        else//菱形刀片
                        {

                        }
                    }
                }
                if (thsc == "S")//直头
                {
                    if (ceatc == "E")//端切
                    {
                        if (sc == "T")//三角形刀片
                        {

                        }
                    }
                    if (ceatc == "S")//侧切
                    {
                        if (sc == "R")//圆形刀片
                        {

                        }
                        else//菱形刀片
                        {

                        }
                    }
                }
            }
            if (sx == "10"&&thsc=="O"&&ceatc=="E")//镗杆偏头端切
            {
                if (sc=="T")//三角形刀片
                {
                    double l = ic * (1 + Math.Cos(pi / 3)) / 2 / Math.Cos(pi / 3) / Math.Sin(pi / 3);
                    Vector2 v1 = new Vector2(0, 0);
                    Vector2 v2 = new Vector2(dcon, 0);
                    Vector2 v3 = new Vector2(v2.X, -lf + lh);
                    Vector2 v4 = new Vector2(0, v3.Y);
                    Vector2 v5 = new Vector2(0, -lf + ecd / Math.Tan(eca));
                    Vector2 v6 = new Vector2(ecd, -lf - l * Math.Cos(kapr));
                    Vector2 v7 = new Vector2(dcon/2+wf - l * Math.Sin(kapr), v6.Y);
                    Vector2 v9 = new Vector2(dcon/2+wf, -lf);
                    Vector2 v8 = new Vector2(v7.X - l * Math.Cos(kapr + pi / 6), v7.Y + l * Math.Sin(kapr + pi / 6));
                    Vector2 v10 = new Vector2(dcon, v9.Y + (wf - dcon/2) * Math.Tan(kapr - pi / 6));
                    Vector2 v11 = new Vector2(dcon/2, -dcon/2 - 5 * scale);
                    Vector2 v15 = new Vector2(v9.X, v7.Y);
                    Vector2 v16 = new Vector2(v5.X, v6.Y);
                    Vector2 v17 = new Vector2(dcon / 2, 2);
                    Vector2 v18 = new Vector2(dcon / 2, v6.Y-2);
                    //线段
                    //主视图
                    Vector2[] Line1 = { v1, v2 };
                    fun.drawBLine(dxf, Line1, 0.3, contour);
                    Vector2[] Line2 = { v2, v10 };
                    fun.drawBLine(dxf, Line2, 0.3, contour);
                    if (ecd != 0)
                    {
                        Vector2[] Line3 = { v1, v5 };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line4 = { v5, v6 };
                        fun.drawBLine(dxf, Line4, 0.3, contour);
                        Vector2[] Line5 = { v6, v7 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    if (ecd == 0)
                    {
                        Vector2[] Line3 = { v1, v16 };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line5 = { v16, v7 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    Vector2[] Line6 = { v7, v9 };
                    fun.drawBLine(dxf, Line6, 0.3, contour);
                    Vector2[] Line7 = { v7, v8 };
                    fun.drawBLine(dxf, Line7, 0.3, contour);
                    Vector2[] Line8 = { v8, v9 };
                    fun.drawBLine(dxf, Line8, 0.3, contour);
                    if (lh != 0)
                    {
                        Vector2[] Line9 = { v3, v4 };
                        fun.drawBLine(dxf, Line9, 0.3, contour);
                    }
                    Circle Circle10 = new Circle(v11, dcon / 2);
                    Circle10.Linetype = Linetype.DashDot;
                    Circle10.Layer = refin;
                    dxf.AddEntity(Circle10);
                    Line Line14 = new Line(v5, v16);
                    Line Line15 = new Line(v9, v15);
                    Line14.Layer = dimensioning;
                    Line15.Layer = dimensioning;
                    dxf.AddEntity(Line14);
                    dxf.AddEntity(Line15);
                    Line Line16 = new Line(v5, v6);
                    Line Line17 = new Line(v9, v7);
                    Line Line18 = new Line(v9, v8);
                    Vector2[] Line19 = { v17, v18 };
                    fun.drawPlinetype(dxf, Line19, 0.15, centre, Linetype.Center);
                    //填充
                    LwPolyline hatchpoly1 = new LwPolyline();
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(new Vector2(0,v11.Y)));
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(new Vector2(v2.X,v11.Y)));
                    hatchpoly1.Vertexes[0].Bulge = 1;
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(new Vector2(0, v11.Y)));
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(new Vector2(v2.X, v11.Y)));
                    hatchpoly1.Vertexes[2].Bulge = -1;
                    hatchpoly1.IsClosed = true;
                    String[] htype1 = new String[100];
                    Line[] hline1 = new Line[100];
                    Arc[] harc1 = new Arc[100];
                    int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                    for (int i = 0; i < hnumst1; i++)
                    {
                        htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                        if (htype1[i] == "Line")
                        {
                            hline1[i] = (Line)hatchpoly1.Explode()[i];
                        }
                        if (htype1[i] == "Arc")
                        {
                            harc1[i] = (Arc)hatchpoly1.Explode()[i];
                        }
                    }
                    fun.hatchsub1(dxf, htype1, hnumst1, 45, 5, hline1, harc1, hatching);
                    //标注样式
                    //箭头样式
                    DimensionStyle dimensionStyle = fun.CreateDimStyle();
                    dimensionStyle.ArrowSize = 3.5;
                    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                    //文本样式
                    dimensionStyle.TextHeight = 3.5;
                    double offset = 10;
                    //线段尺寸标注
                    //尺寸1
                    if (lh != 0)
                    {
                        LinearDimension dim1 = new LinearDimension(new Line(v4, v7), -offset - v7.X / 2, 270, dimensionStyle);
                        dim1.UserText = "LH = " + Math.Round(lh / scale, 2);
                        dxf.AddEntity(dim1);
                    }
                    //尺寸2
                    LinearDimension dim2 = new LinearDimension(new Line(v18, v9), -offset * 5 - (v18.Y + v9.Y) / 2 + v7.Y, 0, dimensionStyle);
                    dim2.UserText = "WF = " + Math.Round(wf / scale, 2);
                    dxf.AddEntity(dim2);
                    //尺寸3
                    LinearDimension dim3 = new LinearDimension(new Line(v2, v9), offset + (v9.X - v2.X) / 2, 270, dimensionStyle);
                    dim3.UserText = "LF = " + Math.Round(lf / scale, 2);
                    dxf.AddEntity(dim3);
                    //尺寸4
                    LinearDimension dim4 = new LinearDimension(new Line(v2, v7), offset * 2 + v9.X - (v2.X + v7.X) / 2, 270, dimensionStyle);
                    dim4.UserText = "OAL = " + Math.Round(-v7.Y / scale, 2);
                    dxf.AddEntity(dim4);
                    if (ecd != 0)
                    {
                        LinearDimension dim5 = new LinearDimension(new Line(v16, v6), -offset*4, 0, dimensionStyle);
                        dim5.UserText = "ECD = " + Math.Round(ecd / scale, 2);
                        dxf.AddEntity(dim5);
                    }
                    //尺寸6
                    LinearDimension dim6 = new LinearDimension(new Line(v1, v2), offset, 0, dimensionStyle);
                    dim6.UserText = "DCON = Φ" + Math.Round(dcon / scale, 2);
                    dxf.AddEntity(dim6);
                    //尺寸11
                    Angular2LineDimension angdim11 = new Angular2LineDimension(Line15, Line17, offset * 2, dimensionStyle);
                    angdim11.UserText = "KAPR = " + Math.Round(kapr / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim11);
                    //尺寸10
                    if (ecd != 0)
                    {
                        Angular2LineDimension angdim10 = new Angular2LineDimension(Line16, Line14, offset, dimensionStyle);
                        angdim10.UserText = "ECA = " + Math.Round(eca / pi * 180, 2) + "°";
                        dxf.AddEntity(angdim10);
                    }
                    //尺寸13
                    Angular2LineDimension angdim13 = new Angular2LineDimension(Line18, Line17, l / 2, dimensionStyle);
                    angdim13.UserText = "EPSR = " + Math.Round(epsr / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim13);
                }
                if (sc=="R")//圆形刀片
                {
                    double icn = ic - s * Math.Tan(an) * 2;
                    Vector2 v1 = new Vector2(0, 0);
                    Vector2 v2 = new Vector2(b, 0);
                    Vector2 v3 = new Vector2(v2.X, -lf + lh);
                    Vector2 v4 = new Vector2(0, v3.Y);
                    Vector2 v7 = new Vector2(dcon/2+wf - ic / 2, -lf + ic / 2);
                    double l = Math.Sqrt((v3.Y - v7.Y) * (v3.Y - v7.Y) + (v7.X - v3.X) * (v7.X - v3.X) - icn * icn / 4);
                    Vector2 v15 = new Vector2((v3.X * icn / 2 / l - v7.Y + v7.X * l / (icn / 2) + v3.Y) / (icn / 2 / l + l / icn * 2), (v7.X - v3.X + v3.Y * icn / 2 / l + v7.Y * l / icn * 2) / (icn / 2 / l + l / icn * 2));
                    double k1 = (v3.Y - v15.Y) / (v3.X - v15.X);
                    double b1 = v3.Y - v3.X * (v3.Y - v15.Y) / (v3.X - v15.X);
                    Vector2 v8 = new Vector2(-(k1 * b1 - v7.X - v7.Y * k1 + Math.Sqrt((k1 * b1 - v7.X - v7.Y * k1) * (k1 * b1 - v7.X - v7.Y * k1) - (1 + k1 * k1) * (v7.X * v7.X + b1 * b1 + v7.Y * v7.Y - 2 * v7.Y * b1 - ic * ic / 4))) / (1 + k1 * k1), -k1 * (k1 * b1 - v7.X - v7.Y * k1 + Math.Sqrt((k1 * b1 - v7.X - v7.Y * k1) * (k1 * b1 - v7.X - v7.Y * k1) - (1 + k1 * k1) * (v7.X * v7.X + b1 * b1 + v7.Y * v7.Y - 2 * v7.Y * b1 - ic * ic / 4))) / (1 + k1 * k1) + b1);
                    Vector2 v14 = new Vector2(v7.X - icn / 2 * Math.Cos(eca), v7.Y - icn / 2 * Math.Sin(eca));
                    Vector2 v5 = new Vector2(0, v14.Y + v14.X / Math.Tan(eca));
                    double k2 = (v5.Y - v14.Y) / (v5.X - v14.X);
                    double b2 = v5.Y - v5.X * (v5.Y - v14.Y) / (v5.X - v14.X);
                    Vector2 v6 = new Vector2(-(k2 * b2 - v7.X - v7.Y * k2 + Math.Sqrt((k2 * b2 - v7.X - v7.Y * k2) * (k2 * b2 - v7.X - v7.Y * k2) - (1 + k2 * k2) * (v7.X * v7.X + b2 * b2 + v7.Y * v7.Y - 2 * v7.Y * b2 - ic * ic / 4))) / (1 + k2 * k2), -k2 * (k2 * b2 - v7.X - v7.Y * k2 + Math.Sqrt((k2 * b2 - v7.X - v7.Y * k2) * (k2 * b2 - v7.X - v7.Y * k2) - (1 + k2 * k2) * (v7.X * v7.X + b2 * b2 + v7.Y * v7.Y - 2 * v7.Y * b2 - ic * ic / 4))) / (1 + k2 * k2) + b2);
                    Vector2 v11 = new Vector2(dcon / 2, -dcon / 2 - 5 * scale);
                    Vector2 v13 = new Vector2(v5.X, v6.Y);
                    Vector2 v17 = new Vector2(dcon / 2, 2);
                    Vector2 v18 = new Vector2(dcon / 2, v7.Y - 2 - ic / 2);
                    //线段
                    //主视图
                    Vector2[] Line1 = { v1, v2 };
                    fun.drawBLine(dxf, Line1, 0.3, contour);
                    Vector2[] Line2 = { v2, v3 };
                    fun.drawBLine(dxf, Line2, 0.3, contour);
                    Vector2[] Line19 = { v3, v8 };
                    fun.drawBLine(dxf, Line19, 0.3, contour);
                    Vector2[] Line20 = { v5, v6 };
                    fun.drawBLine(dxf, Line20, 0.3, contour);
                    Vector2[] Line3 = { v1, v5 };
                    fun.drawBLine(dxf, Line3, 0.3, contour);
                    fun.drawcircle(dxf, v7, ic / 2, 0.3, contour);
                    if (lh != 0)
                    {
                        Vector2[] Line9 = { v3, v4 };
                        fun.drawBLine(dxf, Line9, 0.3, contour);
                    }
                    Circle Circle10 = new Circle(v11, dcon / 2);
                    Circle10.Linetype = Linetype.DashDot;
                    Circle10.Layer = refin;
                    dxf.AddEntity(Circle10);
                    Line Line14 = new Line(v5, v13);
                    Line14.Layer = dimensioning;
                    dxf.AddEntity(Line14);
                    Line Line16 = new Line(v5, v6);
                    Circle circle15 = new Circle(v7, ic / 2);
                    Vector2[] Line18 = { v17, v18 };
                    fun.drawPlinetype(dxf, Line18, 0.15, centre, Linetype.Center);
                    //填充
                    LwPolyline hatchpoly1 = new LwPolyline();
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(new Vector2(0, v11.Y)));
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(new Vector2(v2.X, v11.Y)));
                    hatchpoly1.Vertexes[0].Bulge = 1;
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(new Vector2(0, v11.Y)));
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(new Vector2(v2.X, v11.Y)));
                    hatchpoly1.Vertexes[2].Bulge = -1;
                    hatchpoly1.IsClosed = true;
                    String[] htype1 = new String[100];
                    Line[] hline1 = new Line[100];
                    Arc[] harc1 = new Arc[100];
                    int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                    for (int i = 0; i < hnumst1; i++)
                    {
                        htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                        if (htype1[i] == "Line")
                        {
                            hline1[i] = (Line)hatchpoly1.Explode()[i];
                        }
                        if (htype1[i] == "Arc")
                        {
                            harc1[i] = (Arc)hatchpoly1.Explode()[i];
                        }
                    }
                    fun.hatchsub1(dxf, htype1, hnumst1, 45, 5, hline1, harc1, hatching);
                    //标注样式
                    //箭头样式
                    DimensionStyle dimensionStyle = fun.CreateDimStyle();
                    dimensionStyle.ArrowSize = 0.2;
                    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                    //文本样式
                    dimensionStyle.TextHeight = 1.0;
                    double offset = 10;
                    //线段尺寸标注
                    //尺寸1
                    if (lh != 0)
                    {
                        LinearDimension dim1 = new LinearDimension(new Line(v4, new Vector2(v7.X, v7.Y - ic / 2)), -offset - v7.X / 2, 270, dimensionStyle);
                        dim1.UserText = "LH = " + Math.Round(lh / scale, 2);
                        dxf.AddEntity(dim1);
                    }
                    //尺寸2
                    LinearDimension dim2 = new LinearDimension(new Line(v18, new Vector2(v7.X + ic / 2, v7.Y)), -offset - (v18.Y + v7.Y) / 2 + v7.Y - ic / 2, 0, dimensionStyle);
                    dim2.UserText = "WF = " + Math.Round(wf / scale, 2);
                    dxf.AddEntity(dim2);
                    //尺寸3
                    LinearDimension dim3 = new LinearDimension(new Line(v2, new Vector2(v7.X, v7.Y - ic / 2)), offset + v7.X + ic / 2 - (v7.X + v2.X) / 2, 270, dimensionStyle);
                    dim3.UserText = "LF = " + Math.Round(lf / scale, 2);
                    dxf.AddEntity(dim3);
                    //尺寸6
                    LinearDimension dim6 = new LinearDimension(new Line(v1, v2), offset, 0, dimensionStyle);
                    dim6.UserText = "DCON = Φ" + Math.Round(dcon / scale, 2);
                    dxf.AddEntity(dim6);
                    //尺寸10
                    Angular2LineDimension angdim10 = new Angular2LineDimension(Line16, Line14, offset, dimensionStyle);
                    angdim10.UserText = "ECA = " + Math.Round(eca / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim10);
                    //尺寸11
                    DiametricDimension diadim11 = new DiametricDimension(circle15, 135, offset, dimensionStyle);
                    diadim11.UserText = "IC = φ" + Math.Round(ic / scale, 2);
                    dxf.AddEntity(diadim11);
                }
                else//菱形刀片
                {

                }
            }
            //图框
            if (isframe == 1)
            {
                if (sx == "02")
                {
                    Dictionary<string, Vector2> position = Frame.frameA3Y(dxf, new Vector2(-148.5 + b / 2, 210 - lf / 2));
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
                if (sx == "10")
                {
                    Dictionary<string, Vector2> position = Frame.frameA3Y(dxf, new Vector2(-148.5 + dcon / 2, 210 - lf / 2));
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }
            fun.SetLayer(dxf);

            fun.SetByLayer(dxf);
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void TurningToolForExternalThreading(Dictionary<string, Object> data)  //6.外螺纹车刀
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour");//轮廓层
            Layer dimensioning = new Layer("dimensioning");//尺寸层
            Layer refin = new Layer("refin");//基准线/内轮廓/虚线
            Layer center = new Layer("center");//中心线
            Layer textlayer = new Layer("textlayer");//文本层
            Layer hatching = new Layer("hatching");//填充层
            Layer additionalline = new Layer("additionalline");//附加线
            Layer cutting = new Layer("cutting");//切削层
            dxf.Layers["0"].Lineweight = Lineweight.W25;
            //作图
            //参数
            string path = Convert.ToString(data["path"]);
            double slf = Convert.ToDouble(data["lf"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0)
            {
                if (slf < 67)
                {
                    scale = 4.0;
                }
                else if (slf < 90)
                {
                    scale = 3.0;
                }
                else if (slf < 134)
                {
                    scale = 2.0;
                }
                else if (slf < 178)
                {
                    scale = 1.5;
                }
                else if (slf < 268)
                {
                    scale = 1.0;
                }
                else if (slf < 357)
                {
                    scale = 0.75;
                }
                else
                {
                    scale = 0.5;
                }
            }
            double pi = Math.PI;
            string ceatc = Convert.ToString(data["ceatc"]);
            string thsc = Convert.ToString(data["thsc"]);
            double lf = Convert.ToDouble(data["lf"]) * scale;
            double lh = Convert.ToDouble(data["lh"]) * scale;
            double b = Convert.ToDouble(data["b"]) * scale;
            double h = Convert.ToDouble(data["h"]) * scale;
            double wf = Convert.ToDouble(data["wf"]) * scale;
            double ic = Convert.ToDouble(data["ic"]) * scale;
            double ecd = Convert.ToDouble(data["ecd"]) * scale;
            double kapr = Convert.ToDouble(data["kapr"]) * pi / 180;
            double hea = Convert.ToDouble(data["hea"]) * pi / 180;
            double eca = Convert.ToDouble(data["eca"]) * pi / 180;
            double pdx = Convert.ToDouble(data["pdx"]) * scale;
            double pdy = Convert.ToDouble(data["pdy"]) * scale;
            double s = Convert.ToDouble(data["s"]) * scale;
            double gamo = Convert.ToDouble(data["gamo"]) * pi / 180;
            double kn_0006 = pdx + pdy + Math.Abs(s * Math.Sin(gamo));
            double kn_0004 = Convert.ToDouble(data["kn0004"]) * scale;
            double isframe = Convert.ToDouble(data["isframe"]);
            //坐标
            //主视图
            if (thsc == "O")//偏头
            {
                if (ceatc == "S")//侧切
                {
                    double l = ic * (1 + Math.Cos(pi / 3)) / 2 / Math.Cos(pi / 3) / Math.Sin(pi / 3);
                    Vector2 v1 = new Vector2(0, 0);
                    Vector2 v2 = new Vector2(b, 0);
                    Vector2 v3 = new Vector2(v2.X, -lf + lh);
                    Vector2 v18 = new Vector2(wf - kn_0004, v3.Y - (wf - kn_0004 - b) / Math.Tan(hea));
                    Vector2 v4 = new Vector2(0, v3.Y);
                    Vector2 v7 = new Vector2(wf, -lf);
                    Vector2 v6 = new Vector2(ecd, v7.Y + kn_0006);
                    Vector2 v5 = new Vector2(0, v6.Y + ecd / Math.Tan(eca));
                    Vector2 v9 = new Vector2(v7.X + l * Math.Cos(kapr), v7.Y + l * Math.Sin(kapr));
                    Vector2 v8 = new Vector2(v9.X - l * Math.Sin(pi * 5 / 6 - kapr), v9.Y - l * Math.Cos(5 * pi / 6 - kapr));
                    Vector2 v10 = new Vector2(v18.X, v8.Y + (v18.X - v8.X) * Math.Tan(kapr - pi / 3));
                    Vector2 v11 = new Vector2(v2.X, -h - 5 * scale);
                    Vector2 v12 = new Vector2(0, v11.Y);
                    Vector2 v13 = new Vector2(0, -5 * scale);
                    Vector2 v14 = new Vector2(v11.X, v13.Y);
                    Vector2 v15 = new Vector2(v5.X, v6.Y);
                    Vector2 v16 = new Vector2(v7.X - 5 / Math.Tan(kapr), v7.Y - 10);
                    Vector2 v17 = new Vector2((v8.Y - v6.Y) / Math.Tan(2 * pi / 3 - kapr) + v8.X, v6.Y);
                    Vector2 v19 = new Vector2(v3.X, v18.Y);
                    //线段
                    //主视图
                    Vector2[] Line1 = { v1, v2 };
                    fun.drawBLine(dxf, Line1, 0.3, contour);
                    Vector2[] Line2 = { v2, v3 };
                    fun.drawBLine(dxf, Line2, 0.3, contour);
                    Vector2[] Line7 = { v3, v18 };
                    fun.drawBLine(dxf, Line7, 0.3, contour);
                    Vector2[] Line8 = { v18, v10 };
                    fun.drawBLine(dxf, Line8, 0.3, contour);
                    Vector2[] Line19 = { v7, v8 };
                    fun.drawBLine(dxf, Line19, 0.3, contour);
                    Vector2[] Line20 = { v8, v9 };
                    fun.drawBLine(dxf, Line20, 0.3, contour);
                    if (ecd != 0)
                    {
                        Vector2[] Line3 = { v1, v5 };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line4 = { v5, v6 };
                        fun.drawBLine(dxf, Line4, 0.3, contour);
                        Vector2[] Line5 = { v6, v17 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    if (ecd == 0)
                    {
                        Vector2[] Line3 = { v1, v15 };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line5 = { v15, v17 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    Vector2[] Line6 = { v7, v9 };
                    fun.drawBLine(dxf, Line6, 0.3, contour);
                    if (lh != 0)
                    {
                        Vector2[] Line9 = { v3, v4 };
                        fun.drawBLine(dxf, Line9, 0.3, contour);
                    }
                    Vector2[] Line10 = { v11, v12 };
                    fun.drawPlinetype(dxf, Line10, 0.15, refin, Linetype.DashDot);
                    Vector2[] Line11 = { v13, v14 };
                    fun.drawPlinetype(dxf, Line11, 0.15, refin, Linetype.DashDot);
                    Line Line12 = new Line(v11, v12);
                    Line Line13 = new Line(v13, v14);
                    Line Line14 = new Line(v5, v15);
                    Line Line15 = new Line(v7, v16);
                    Line14.Layer = dimensioning;
                    Line15.Layer = dimensioning;
                    dxf.AddEntity(Line14);
                    dxf.AddEntity(Line15);
                    Line Line16 = new Line(v5, v6);
                    Line Line17 = new Line(v7, new Vector2(v7.X - 10, v7.Y));
                    Line17.Layer = dimensioning;
                    dxf.AddEntity(Line17);
                    Line Line18 = new Line(v3, v19);
                    Line18.Layer = dimensioning;
                    dxf.AddEntity(Line18);
                    Line Line21 = new Line(v3, v18);
                    //填充
                    LwPolyline hatchpoly3 = new LwPolyline();
                    hatchpoly3.Vertexes.Add(new LwPolylineVertex(v11));
                    hatchpoly3.Vertexes.Add(new LwPolylineVertex(v12));
                    hatchpoly3.Vertexes.Add(new LwPolylineVertex(v13));
                    hatchpoly3.Vertexes.Add(new LwPolylineVertex(v14));
                    hatchpoly3.IsClosed = true;
                    String[] htype3 = new String[100];
                    Line[] hline3 = new Line[100];
                    int hnumst3 = hatchpoly3.Explode().Count;  //记录爆炸后，线段有多少
                    for (int i = 0; i < hnumst3; i++)
                    {
                        htype3[i] = hatchpoly3.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                        if (htype3[i] == "Line")
                        {
                            hline3[i] = (Line)hatchpoly3.Explode()[i];
                        }
                    }
                    fun.hatchsubofline(dxf, htype3, hnumst3, 45, 5, hline3, hatching);
                    //标注样式
                    //箭头样式
                    DimensionStyle dimensionStyle = fun.CreateDimStyle();
                    dimensionStyle.ArrowSize = 0.2;
                    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                    //文本样式
                    dimensionStyle.TextHeight = 1.0;
                    double offset = 10;
                    //线段尺寸标注
                    //尺寸1
                    if (lh != 0)
                    {
                        LinearDimension dim1 = new LinearDimension(new Line(v4, v7), -offset - v7.X / 2, 270, dimensionStyle);
                        dim1.UserText = "LH = " + Math.Round(lh / scale, 2);
                        dxf.AddEntity(dim1);
                    }
                    //尺寸2
                    LinearDimension dim2 = new LinearDimension(new Line(v4, v7), -offset * 4 - (v4.Y - v7.Y) / 2, 0, dimensionStyle);
                    dim2.UserText = "WF = " + Math.Round(wf / scale, 2);
                    dxf.AddEntity(dim2);
                    //尺寸3
                    LinearDimension dim3 = new LinearDimension(new Line(v2, v7), offset + (v7.X - v2.X) / 2, 270, dimensionStyle);
                    dim3.UserText = "LF = " + Math.Round(lf / scale, 2);
                    dxf.AddEntity(dim3);
                    //尺寸5
                    if (ecd != 0)
                    {
                        LinearDimension dim5 = new LinearDimension(new Line(v5, v6), -offset*2 - (v5.Y + v6.Y) / 2 + v7.Y, 0, dimensionStyle);
                        dim5.UserText = "ECD = " + Math.Round(ecd / scale, 2);
                        dxf.AddEntity(dim5);
                    }
                    //尺寸6
                    LinearDimension dim6 = new LinearDimension(new Line(v1, v2), offset, 0, dimensionStyle);
                    dim6.UserText = "B = " + Math.Round(b / scale, 2);
                    dxf.AddEntity(dim6);
                    //尺寸7
                    Angular2LineDimension angdim7 = new Angular2LineDimension(Line18, Line21, offset, dimensionStyle);
                    angdim7.UserText = "HEA = " + Math.Round(hea / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim7);
                    //尺寸11
                    Angular2LineDimension angdim11 = new Angular2LineDimension(Line17, Line15, offset, dimensionStyle);
                    angdim11.UserText = "KAPR = " + Math.Round(kapr / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim11);
                    //尺寸10
                    if (ecd != 0)
                    {
                        Angular2LineDimension angdim10 = new Angular2LineDimension(Line16, Line14, offset, dimensionStyle);
                        angdim10.UserText = "ECA = " + Math.Round(eca / pi * 180, 2) + "°";
                        dxf.AddEntity(angdim10);
                    }
                    //尺寸12
                    LinearDimension dim12 = new LinearDimension(new Line(v12, v13), -offset, 270, dimensionStyle);
                    dim12.UserText = "H = " + Math.Round(h / scale, 2);
                    dxf.AddEntity(dim12);
                }
                if (ceatc == "E")//端切
                {
                    double l = ic * (1 + Math.Cos(pi / 3)) / 2 / Math.Cos(pi / 3) / Math.Sin(pi / 3);
                    Vector2 v1 = new Vector2(0, 0);
                    Vector2 v2 = new Vector2(b, 0);
                    Vector2 v3 = new Vector2(v2.X, -lf + lh);
                    Vector2 v18 = new Vector2(wf - kn_0004, v3.Y - (wf - kn_0004 - b) / Math.Tan(hea));
                    Vector2 v4 = new Vector2(0, v3.Y);
                    Vector2 v7 = new Vector2(wf, -lf);
                    Vector2 v6 = new Vector2(ecd, v7.Y + kn_0006);
                    Vector2 v5 = new Vector2(0, v6.Y + ecd / Math.Tan(eca));
                    Vector2 v9 = new Vector2(v7.X - l * Math.Sin(pi * 2 / 3 - kapr), v7.Y + l * Math.Cos(pi * 2 / 3 - kapr));
                    Vector2 v8 = new Vector2(v7.X - l * Math.Cos(kapr - pi / 2), v7.Y + l * Math.Sin(kapr - pi / 2));
                    Vector2 v10 = new Vector2(v18.X, v7.Y + (v7.X - v18.X) / Math.Tan(pi * 2 / 3 - kapr));
                    Vector2 v11 = new Vector2(v2.X, -h - 5 * scale);
                    Vector2 v12 = new Vector2(0, v11.Y);
                    Vector2 v13 = new Vector2(0, -5 * scale);
                    Vector2 v14 = new Vector2(v11.X, v13.Y);
                    Vector2 v15 = new Vector2(v5.X, v6.Y);
                    Vector2 v16 = new Vector2(v7.X, v7.Y - 10);
                    Vector2 v17 = new Vector2((v6.Y - v8.Y) / Math.Tan(5 * pi / 6 - kapr) + v8.X, v6.Y);
                    Vector2 v19 = new Vector2(v3.X, v18.Y);
                    //线段
                    //主视图
                    Vector2[] Line1 = { v1, v2 };
                    fun.drawBLine(dxf, Line1, 0.3, contour);
                    Vector2[] Line2 = { v2, v3 };
                    fun.drawBLine(dxf, Line2, 0.3, contour);
                    Vector2[] Line7 = { v3, v18 };
                    fun.drawBLine(dxf, Line7, 0.3, contour);
                    Vector2[] Line8 = { v18, v10 };
                    fun.drawBLine(dxf, Line8, 0.3, contour);
                    Vector2[] Line19 = { v7, v8 };
                    fun.drawBLine(dxf, Line19, 0.3, contour);
                    Vector2[] Line20 = { v8, v9 };
                    fun.drawBLine(dxf, Line20, 0.3, contour);
                    if (ecd != 0)
                    {
                        Vector2[] Line3 = { v1, v5 };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line4 = { v5, v6 };
                        fun.drawBLine(dxf, Line4, 0.3, contour);
                        Vector2[] Line5 = { v6, v17 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    if (ecd == 0)
                    {
                        Vector2[] Line3 = { v1, v15 };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line5 = { v15, v17 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    Vector2[] Line6 = { v7, v9 };
                    fun.drawBLine(dxf, Line6, 0.3, contour);
                    if (lh != 0)
                    {
                        Vector2[] Line9 = { v3, v4 };
                        fun.drawBLine(dxf, Line9, 0.3, contour);
                    }
                    Vector2[] Line10 = { v11, v12 };
                    fun.drawPlinetype(dxf, Line10, 0.15, refin, Linetype.DashDot);
                    Vector2[] Line11 = { v13, v14 };
                    fun.drawPlinetype(dxf, Line11, 0.15, refin, Linetype.DashDot);
                    Line Line12 = new Line(v11, v12);
                    Line Line13 = new Line(v13, v14);
                    Line Line14 = new Line(v5, v15);
                    Line Line15 = new Line(v7, v16);
                    Line14.Layer = dimensioning;
                    Line15.Layer = dimensioning;
                    dxf.AddEntity(Line14);
                    dxf.AddEntity(Line15);
                    Line Line16 = new Line(v5, v6);
                    Line Line17 = new Line(v7, v8);
                    Line Line18 = new Line(v3, v19);
                    Line18.Layer = dimensioning;
                    dxf.AddEntity(Line18);
                    Line Line21 = new Line(v3, v18);
                    //填充
                    LwPolyline hatchpoly3 = new LwPolyline();
                    hatchpoly3.Vertexes.Add(new LwPolylineVertex(v11));
                    hatchpoly3.Vertexes.Add(new LwPolylineVertex(v12));
                    hatchpoly3.Vertexes.Add(new LwPolylineVertex(v13));
                    hatchpoly3.Vertexes.Add(new LwPolylineVertex(v14));
                    hatchpoly3.IsClosed = true;
                    String[] htype3 = new String[100];
                    Line[] hline3 = new Line[100];
                    int hnumst3 = hatchpoly3.Explode().Count;  //记录爆炸后，线段有多少
                    for (int i = 0; i < hnumst3; i++)
                    {
                        htype3[i] = hatchpoly3.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                        if (htype3[i] == "Line")
                        {
                            hline3[i] = (Line)hatchpoly3.Explode()[i];
                        }
                    }
                    fun.hatchsubofline(dxf, htype3, hnumst3, 45, 5, hline3, hatching);
                    //标注样式
                    //箭头样式
                    DimensionStyle dimensionStyle = fun.CreateDimStyle();
                    dimensionStyle.ArrowSize = 0.2;
                    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                    //文本样式
                    dimensionStyle.TextHeight = 1.0;
                    double offset = 10;
                    //线段尺寸标注
                    //尺寸1
                    if (lh != 0)
                    {
                        LinearDimension dim1 = new LinearDimension(new Line(v4, v7), -offset - v7.X / 2, 270, dimensionStyle);
                        dim1.UserText = "LH = " + Math.Round(lh / scale, 2);
                        dxf.AddEntity(dim1);
                    }
                    //尺寸2
                    LinearDimension dim2 = new LinearDimension(new Line(v4, v7), -offset * 4 - (v4.Y - v7.Y) / 2, 0, dimensionStyle);
                    dim2.UserText = "WF = " + Math.Round(wf / scale, 2);
                    dxf.AddEntity(dim2);
                    //尺寸3
                    LinearDimension dim3 = new LinearDimension(new Line(v2, v7), offset + (v7.X - v2.X) / 2, 270, dimensionStyle);
                    dim3.UserText = "LF = " + Math.Round(lf / scale, 2);
                    dxf.AddEntity(dim3);
                    //尺寸5
                    if (ecd != 0)
                    {
                        LinearDimension dim5 = new LinearDimension(new Line(v5, v6), -offset*2 - (v5.Y + v6.Y) / 2 + v7.Y, 0, dimensionStyle);
                        dim5.UserText = "ECD = " + Math.Round(ecd / scale, 2);
                        dxf.AddEntity(dim5);
                    }
                    //尺寸6
                    LinearDimension dim6 = new LinearDimension(new Line(v1, v2), offset, 0, dimensionStyle);
                    dim6.UserText = "B = " + Math.Round(b / scale, 2);
                    dxf.AddEntity(dim6);
                    //尺寸7
                    Angular2LineDimension angdim7 = new Angular2LineDimension(Line18, Line21, offset, dimensionStyle);
                    angdim7.UserText = "HEA = " + Math.Round(hea / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim7);
                    //尺寸11
                    Angular2LineDimension angdim11 = new Angular2LineDimension(Line17, Line15, offset, dimensionStyle);
                    angdim11.UserText = "KAPR = " + Math.Round(kapr / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim11);
                    //尺寸10
                    if (ecd != 0)
                    {
                        Angular2LineDimension angdim10 = new Angular2LineDimension(Line16, Line14, offset, dimensionStyle);
                        angdim10.UserText = "ECA = " + Math.Round(eca / pi * 180, 2) + "°";
                        dxf.AddEntity(angdim10);
                    }
                    //尺寸12
                    LinearDimension dim12 = new LinearDimension(new Line(v12, v13), -offset, 270, dimensionStyle);
                    dim12.UserText = "H = " + Math.Round(h / scale, 2);
                    dxf.AddEntity(dim12);
                }
            }
            if (thsc == "S")//直头
            {
                if (ceatc == "S")//侧切
                {
                    double l = ic * (1 + Math.Cos(pi / 3)) / 2 / Math.Cos(pi / 3) / Math.Sin(pi / 3);
                    Vector2 v1 = new Vector2(0, 0);
                    Vector2 v2 = new Vector2(b, 0);
                    Vector2 v3 = new Vector2(v2.X, -lf + lh);
                    Vector2 v4 = new Vector2(0, v3.Y);
                    Vector2 v7 = new Vector2(wf, -lf);
                    Vector2 v6 = new Vector2(ecd, v7.Y + kn_0006);
                    Vector2 v5 = new Vector2(0, v6.Y + ecd / Math.Tan(eca));
                    Vector2 v9 = new Vector2(v7.X+l*Math.Cos(kapr), v7.Y+l * Math.Sin(kapr));
                    Vector2 v8 = new Vector2(v9.X - l * Math.Sin(pi*5 / 6-kapr), v9.Y - l * Math.Cos(5*pi / 6-kapr));
                    Vector2 v10 = new Vector2(v3.X, v8.Y + (v3.X-v8.X) * Math.Tan(kapr-pi/3));
                    Vector2 v11 = new Vector2(v2.X, -h - 5 * scale);
                    Vector2 v12 = new Vector2(0, v11.Y);
                    Vector2 v13 = new Vector2(0, -5 * scale);
                    Vector2 v14 = new Vector2(v11.X, v13.Y);
                    Vector2 v15 = new Vector2(v5.X, v6.Y);
                    Vector2 v16 = new Vector2(v7.X-5/Math.Tan(kapr), v7.Y-10);
                    Vector2 v17 = new Vector2((v8.Y-v6.Y)/Math.Tan(2*pi/3-kapr)+v8.X, v6.Y);
                    //线段
                    //主视图
                    Vector2[] Line1 = { v1, v2 };
                    fun.drawBLine(dxf, Line1, 0.3, contour);
                    Vector2[] Line2 = { v2, v10 };
                    fun.drawBLine(dxf, Line2, 0.3, contour);
                    Vector2[] Line19 = { v7, v8 };
                    fun.drawBLine(dxf, Line19, 0.3, contour);
                    Vector2[] Line20 = { v8, v9 };
                    fun.drawBLine(dxf, Line20, 0.3, contour);
                    if (ecd != 0)
                    {
                        Vector2[] Line3 = { v1, v5 };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line4 = { v5, v6 };
                        fun.drawBLine(dxf, Line4, 0.3, contour);
                        Vector2[] Line5 = { v6, v17 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    if (ecd == 0)
                    {
                        Vector2[] Line3 = { v1, v15 };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line5 = { v15, v17 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    Vector2[] Line6 = { v7, v9 };
                    fun.drawBLine(dxf, Line6, 0.3, contour);
                    if (lh != 0)
                    {
                        Vector2[] Line9 = { v3, v4 };
                        fun.drawBLine(dxf, Line9, 0.3, contour);
                    }
                    Vector2[] Line10 = { v11, v12 };
                    fun.drawPlinetype(dxf, Line10, 0.15, refin, Linetype.DashDot);
                    Vector2[] Line11 = { v13, v14 };
                    fun.drawPlinetype(dxf, Line11, 0.15, refin, Linetype.DashDot);
                    Line Line12 = new Line(v11, v12);
                    Line Line13 = new Line(v13, v14);
                    Line Line14 = new Line(v5, v15);
                    Line Line15 = new Line(v7, v16);
                    Line14.Layer = dimensioning;
                    Line15.Layer = dimensioning;
                    dxf.AddEntity(Line14);
                    dxf.AddEntity(Line15);
                    Line Line16 = new Line(v5, v6);
                    Line Line17 = new Line(v7, new Vector2(v7.X - 10, v7.Y));
                    Line17.Layer = dimensioning;
                    dxf.AddEntity(Line17);
                    //填充
                    LwPolyline hatchpoly3 = new LwPolyline();
                    hatchpoly3.Vertexes.Add(new LwPolylineVertex(v11));
                    hatchpoly3.Vertexes.Add(new LwPolylineVertex(v12));
                    hatchpoly3.Vertexes.Add(new LwPolylineVertex(v13));
                    hatchpoly3.Vertexes.Add(new LwPolylineVertex(v14));
                    hatchpoly3.IsClosed = true;
                    String[] htype3 = new String[100];
                    Line[] hline3 = new Line[100];
                    int hnumst3 = hatchpoly3.Explode().Count;  //记录爆炸后，线段有多少
                    for (int i = 0; i < hnumst3; i++)
                    {
                        htype3[i] = hatchpoly3.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                        if (htype3[i] == "Line")
                        {
                            hline3[i] = (Line)hatchpoly3.Explode()[i];
                        }
                    }
                    fun.hatchsubofline(dxf, htype3, hnumst3, 45, 5, hline3, hatching);
                    //标注样式
                    //箭头样式
                    DimensionStyle dimensionStyle = fun.CreateDimStyle();
                    dimensionStyle.ArrowSize = 0.2;
                    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                    //文本样式
                    dimensionStyle.TextHeight = 1.0;
                    double offset = 10;
                    //线段尺寸标注
                    //尺寸1
                    if (lh != 0)
                    {
                        LinearDimension dim1 = new LinearDimension(new Line(v4, v7), -offset - v7.X / 2, 270, dimensionStyle);
                        dim1.UserText = "LH = " + Math.Round(lh / scale, 2);
                        dxf.AddEntity(dim1);
                    }
                    //尺寸2
                    LinearDimension dim2 = new LinearDimension(new Line(v4, v7), -offset * 4 - (v4.Y - v7.Y) / 2, 0, dimensionStyle);
                    dim2.UserText = "WF = " + Math.Round(wf / scale, 2);
                    dxf.AddEntity(dim2);
                    //尺寸3
                    LinearDimension dim3 = new LinearDimension(new Line(v2, v7), offset + (v7.X - v2.X) / 2, 270, dimensionStyle);
                    dim3.UserText = "LF = " + Math.Round(lf / scale, 2);
                    dxf.AddEntity(dim3);
                    //尺寸5
                    if (ecd != 0)
                    {
                        LinearDimension dim5 = new LinearDimension(new Line(v5, v6), -offset*2-(v5.Y+v6.Y)/2+v7.Y, 0, dimensionStyle);
                        dim5.UserText = "ECD = " + Math.Round(ecd / scale, 2);
                        dxf.AddEntity(dim5);
                    }
                    //尺寸6
                    LinearDimension dim6 = new LinearDimension(new Line(v1, v2), offset, 0, dimensionStyle);
                    dim6.UserText = "B = " + Math.Round(b / scale, 2);
                    dxf.AddEntity(dim6);
                    //尺寸11
                    Angular2LineDimension angdim11 = new Angular2LineDimension(Line17, Line15, offset, dimensionStyle);
                    angdim11.UserText = "KAPR = " + Math.Round(kapr / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim11);
                    //尺寸10
                    if (ecd != 0)
                    {
                        Angular2LineDimension angdim10 = new Angular2LineDimension(Line16, Line14, offset, dimensionStyle);
                        angdim10.UserText = "ECA = " + Math.Round(eca / pi * 180, 2) + "°";
                        dxf.AddEntity(angdim10);
                    }
                    //尺寸12
                    LinearDimension dim12 = new LinearDimension(new Line(v12, v13), -offset, 270, dimensionStyle);
                    dim12.UserText = "H = " + Math.Round(h / scale, 2);
                    dxf.AddEntity(dim12);
                }
                if (ceatc == "E")//端切
                {
                    double l = ic * (1 + Math.Cos(pi / 3)) / 2 / Math.Cos(pi / 3) / Math.Sin(pi / 3);
                    Vector2 v1 = new Vector2(0, 0);
                    Vector2 v2 = new Vector2(b, 0);
                    Vector2 v3 = new Vector2(v2.X, -lf + lh);
                    Vector2 v4 = new Vector2(0, v3.Y);
                    Vector2 v7 = new Vector2(wf, -lf);
                    Vector2 v6 = new Vector2(ecd, v7.Y + kn_0006);
                    Vector2 v5 = new Vector2(0, v6.Y + ecd / Math.Tan(eca));
                    Vector2 v9 = new Vector2(v7.X - l * Math.Sin(pi*2/3-kapr), v7.Y + l * Math.Cos(pi*2/3-kapr));
                    Vector2 v8 = new Vector2(v7.X - l * Math.Cos(kapr-pi/2), v7.Y + l * Math.Sin(kapr-pi/2));
                    Vector2 v10 = new Vector2(v3.X, v7.Y + (v7.X - v3.X) / Math.Tan(pi * 2 / 3 - kapr));
                    Vector2 v11 = new Vector2(v2.X, -h - 5 * scale);
                    Vector2 v12 = new Vector2(0, v11.Y);
                    Vector2 v13 = new Vector2(0, -5 * scale);
                    Vector2 v14 = new Vector2(v11.X, v13.Y);
                    Vector2 v15 = new Vector2(v5.X, v6.Y);
                    Vector2 v16 = new Vector2(v7.X, v7.Y - 10);
                    Vector2 v17 = new Vector2((v6.Y - v8.Y) / Math.Tan(5 * pi / 6 - kapr) + v8.X, v6.Y);
                    //线段
                    //主视图
                    Vector2[] Line1 = { v1, v2 };
                    fun.drawBLine(dxf, Line1, 0.3, contour);
                    Vector2[] Line2 = { v2, v10 };
                    fun.drawBLine(dxf, Line2, 0.3, contour);
                    Vector2[] Line19 = { v7, v8 };
                    fun.drawBLine(dxf, Line19, 0.3, contour);
                    Vector2[] Line20 = { v8, v9 };
                    fun.drawBLine(dxf, Line20, 0.3, contour);
                    if (ecd != 0)
                    {
                        Vector2[] Line3 = { v1, v5 };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line4 = { v5, v6 };
                        fun.drawBLine(dxf, Line4, 0.3, contour);
                        Vector2[] Line5 = { v6, v17 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    if (ecd == 0)
                    {
                        Vector2[] Line3 = { v1, v15 };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line5 = { v15, v17 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    Vector2[] Line6 = { v7, v9 };
                    fun.drawBLine(dxf, Line6, 0.3, contour);
                    if (lh != 0)
                    {
                        Vector2[] Line9 = { v3, v4 };
                        fun.drawBLine(dxf, Line9, 0.3, contour);
                    }
                    Vector2[] Line10 = { v11, v12 };
                    fun.drawPlinetype(dxf, Line10, 0.15, refin, Linetype.DashDot);
                    Vector2[] Line11 = { v13, v14 };
                    fun.drawPlinetype(dxf, Line11, 0.15, refin, Linetype.DashDot);
                    Line Line12 = new Line(v11, v12);
                    Line Line13 = new Line(v13, v14);
                    Line Line14 = new Line(v5, v15);
                    Line Line15 = new Line(v7, v16);
                    Line14.Layer = dimensioning;
                    Line15.Layer = dimensioning;
                    dxf.AddEntity(Line14);
                    dxf.AddEntity(Line15);
                    Line Line16 = new Line(v5, v6);
                    Line Line17 = new Line(v7, v8);
                    //填充
                    LwPolyline hatchpoly3 = new LwPolyline();
                    hatchpoly3.Vertexes.Add(new LwPolylineVertex(v11));
                    hatchpoly3.Vertexes.Add(new LwPolylineVertex(v12));
                    hatchpoly3.Vertexes.Add(new LwPolylineVertex(v13));
                    hatchpoly3.Vertexes.Add(new LwPolylineVertex(v14));
                    hatchpoly3.IsClosed = true;
                    String[] htype3 = new String[100];
                    Line[] hline3 = new Line[100];
                    int hnumst3 = hatchpoly3.Explode().Count;  //记录爆炸后，线段有多少
                    for (int i = 0; i < hnumst3; i++)
                    {
                        htype3[i] = hatchpoly3.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                        if (htype3[i] == "Line")
                        {
                            hline3[i] = (Line)hatchpoly3.Explode()[i];
                        }
                    }
                    fun.hatchsubofline(dxf, htype3, hnumst3, 45, 5, hline3, hatching);
                    //标注样式
                    //箭头样式
                    DimensionStyle dimensionStyle = fun.CreateDimStyle();
                    dimensionStyle.ArrowSize = 0.2;
                    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                    //文本样式
                    dimensionStyle.TextHeight = 1.0;
                    double offset = 10;
                    //线段尺寸标注
                    //尺寸1
                    if (lh != 0)
                    {
                        LinearDimension dim1 = new LinearDimension(new Line(v4, v7), -offset - v7.X / 2, 270, dimensionStyle);
                        dim1.UserText = "LH = " + Math.Round(lh / scale, 2);
                        dxf.AddEntity(dim1);
                    }
                    //尺寸2
                    LinearDimension dim2 = new LinearDimension(new Line(v4, v7), -offset * 4 - (v4.Y - v7.Y) / 2, 0, dimensionStyle);
                    dim2.UserText = "WF = " + Math.Round(wf / scale, 2);
                    dxf.AddEntity(dim2);
                    //尺寸3
                    LinearDimension dim3 = new LinearDimension(new Line(v2, v7), offset + (v7.X - v2.X) / 2, 270, dimensionStyle);
                    dim3.UserText = "LF = " + Math.Round(lf / scale, 2);
                    dxf.AddEntity(dim3);
                    //尺寸5
                    if (ecd != 0)
                    {
                        LinearDimension dim5 = new LinearDimension(new Line(v5, v6), -offset*2 - (v5.Y + v6.Y) / 2 + v7.Y, 0, dimensionStyle);
                        dim5.UserText = "ECD = " + Math.Round(ecd / scale, 2);
                        dxf.AddEntity(dim5);
                    }
                    //尺寸6
                    LinearDimension dim6 = new LinearDimension(new Line(v1, v2), offset, 0, dimensionStyle);
                    dim6.UserText = "B = " + Math.Round(b / scale, 2);
                    dxf.AddEntity(dim6);
                    //尺寸11
                    Angular2LineDimension angdim11 = new Angular2LineDimension(Line17, Line15, offset, dimensionStyle);
                    angdim11.UserText = "KAPR = " + Math.Round(kapr / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim11);
                    //尺寸10
                    if (ecd != 0)
                    {
                        Angular2LineDimension angdim10 = new Angular2LineDimension(Line16, Line14, offset, dimensionStyle);
                        angdim10.UserText = "ECA = " + Math.Round(eca / pi * 180, 2) + "°";
                        dxf.AddEntity(angdim10);
                    }
                    //尺寸12
                    LinearDimension dim12 = new LinearDimension(new Line(v12, v13), -offset, 270, dimensionStyle);
                    dim12.UserText = "H = " + Math.Round(h / scale, 2);
                    dxf.AddEntity(dim12);
                }
            }
            //图框
            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA3Y(dxf, new Vector2(-148.5 + b / 2, 210 - lf / 2));
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }
            fun.SetLayer(dxf);

            fun.SetByLayer(dxf);
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void BoringBarForInternalThreading(Dictionary<string, Object> data)  //7.内螺纹镗杆
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
            //作图
            //参数
            string path = Convert.ToString(data["path"]);
            double slf = Convert.ToDouble(data["lf"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0)
            {
                if (slf < 67)
                {
                    scale = 4.0;
                }
                else if (slf < 90)
                {
                    scale = 3.0;
                }
                else if (slf < 134)
                {
                    scale = 2.0;
                }
                else if (slf < 178)
                {
                    scale = 1.5;
                }
                else if (slf < 268)
                {
                    scale = 1.0;
                }
                else if (slf < 357)
                {
                    scale = 0.75;
                }
                else
                {
                    scale = 0.5;
                }
            }
            double pi = Math.PI;
            string ceatc = Convert.ToString(data["ceatc"]);
            double lf = Convert.ToDouble(data["lf"]) * scale;
            double lh = Convert.ToDouble(data["lh"]) * scale;
            double dcon = Convert.ToDouble(data["dcon"]) * scale;
            double bdred = Convert.ToDouble(data["bdred"]) * scale;
            double ldred = Convert.ToDouble(data["ldred"]) * scale;
            double wf = Convert.ToDouble(data["wf"]) * scale;
            double ic = Convert.ToDouble(data["ic"]) * scale;
            double ecd = Convert.ToDouble(data["ecd"]) * scale;
            double kapr = Convert.ToDouble(data["kapr"]) * pi / 180;
            double hea = Convert.ToDouble(data["hea"]) * pi / 180;
            double eca = Convert.ToDouble(data["eca"]) * pi / 180;
            double pdx = Convert.ToDouble(data["pdx"]) * scale;
            double pdy = Convert.ToDouble(data["pdy"]) * scale;
            double s = Convert.ToDouble(data["s"]) * scale;
            double gamo = Convert.ToDouble(data["gamo"]) * pi / 180;
            double kn_0006 = pdx + pdy + Math.Abs(s * Math.Sin(gamo));
            double kn_0004 = Convert.ToDouble(data["kn0004"]) * scale;
            double isframe = Convert.ToDouble(data["isframe"]);
            //坐标
            //主视图
                if (ceatc == "S")//侧切
                {
                    double l = ic * (1 + Math.Cos(pi / 3)) / 2 / Math.Cos(pi / 3) / Math.Sin(pi / 3);
                    Vector2 v1 = new Vector2(-dcon / 2, 0);
                    Vector2 v2 = new Vector2(dcon / 2, 0);
                    Vector2 v3 = new Vector2(bdred / 2, -lf + lh);
                    Vector2 v18 = new Vector2(wf - kn_0004, v3.Y - (wf - kn_0004 - bdred / 2) / Math.Tan(hea));
                    Vector2 v4 = new Vector2(v2.X, -lf + ldred);
                    Vector2 v7 = new Vector2(wf, -lf);
                    Vector2 v6 = new Vector2(-v18.X + ecd, v7.Y + kn_0006);
                    Vector2 v5 = new Vector2(-v18.X, v6.Y + ecd / Math.Tan(eca));
                    Vector2 v9 = new Vector2(v7.X + l * Math.Cos(kapr), v7.Y + l * Math.Sin(kapr));
                    Vector2 v8 = new Vector2(v9.X - l * Math.Sin(pi * 5 / 6 - kapr), v9.Y - l * Math.Cos(5 * pi / 6 - kapr));
                    Vector2 v10 = new Vector2(v18.X, v8.Y + (v18.X - v8.X) * Math.Tan(kapr - pi / 3));
                    Vector2 v11 = new Vector2(0, -dcon / 2 - 5 * scale);
                    Vector2 v12 = new Vector2(-v4.X, v4.Y);
                    Vector2 v13 = new Vector2(-bdred / 2, v12.Y - (dcon - bdred) / 2);
                    Vector2 v14 = new Vector2(-v13.X, v13.Y);
                    Vector2 v15 = new Vector2(v5.X, v6.Y);
                    Vector2 v16 = new Vector2(v7.X, v7.Y - 10);
                    Vector2 v17 = new Vector2((v8.Y - v6.Y) / Math.Tan(2 * pi / 3 - kapr) + v8.X, v6.Y);
                    Vector2 v19 = new Vector2(v3.X, v18.Y);
                    Vector2 v20 = new Vector2(-v3.X, v3.Y);
                    Vector2 v21 = new Vector2(-v18.X, v18.Y);
                    Vector2 v22 = new Vector2(0, 2);
                    Vector2 v23 = new Vector2(0, v7.Y - 2);
                    //线段
                    //主视图
                    Vector2[] Line1 = { v1, v2 };
                    fun.drawBLine(dxf, Line1, 0.3, contour);
                    Vector2[] Line2 = { v2, v4 };
                    fun.drawBLine(dxf, Line2, 0.3, contour);
                    Vector2[] Line7 = { v4, v14 };
                    fun.drawBLine(dxf, Line7, 0.3, contour);
                    Vector2[] Line8 = { v14, v3 };
                    fun.drawBLine(dxf, Line8, 0.3, contour);
                    Vector2[] Line9 = { v3, v18 };
                    fun.drawBLine(dxf, Line9, 0.3, contour);
                    Vector2[] Line10 = { v18, v10 };
                    fun.drawBLine(dxf, Line10, 0.3, contour);
                    Vector2[] Line19 = { v7, v8 };
                    fun.drawBLine(dxf, Line19, 0.3, contour);
                    Vector2[] Line20 = { v8, v9 };
                    fun.drawBLine(dxf, Line20, 0.3, contour);
                    if (ecd != 0)
                    {
                        Vector2[] Line3 = { v21, v5 };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line4 = { v5, v6 };
                        fun.drawBLine(dxf, Line4, 0.3, contour);
                        Vector2[] Line5 = { v6, v17 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    if (ecd == 0)
                    {
                        Vector2[] Line3 = { v21, v15 };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line5 = { v15, v17 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    Vector2[] Line6 = { v7, v9 };
                    fun.drawBLine(dxf, Line6, 0.3, contour);
                    Vector2[] Line11 = { v6, v17 };
                    fun.drawBLine(dxf, Line11, 0.3, contour);
                    Vector2[] Line12 = { v1, v12 };
                    fun.drawBLine(dxf, Line12, 0.3, contour);
                    Vector2[] Line13 = { v12, v13 };
                    fun.drawBLine(dxf, Line13, 0.3, contour);
                    Vector2[] Line14 = { v20, v13 };
                    fun.drawBLine(dxf, Line14, 0.3, contour);
                    Vector2[] Line15 = { v20, v21 };
                    fun.drawBLine(dxf, Line15, 0.3, contour);
                    Vector2[] Line16 = { v12, v4 };
                    fun.drawBLine(dxf, Line16, 0.3, contour);
                    Vector2[] Line17 = { v14, v13 };
                    fun.drawBLine(dxf, Line17, 0.3, contour);
                    Line Line18 = new Line(v5, v15);
                    Line Line21 = new Line(v7, v16);
                    Line18.Layer = dimensioning;
                    Line21.Layer = dimensioning;
                    dxf.AddEntity(Line18);
                    dxf.AddEntity(Line21);
                    Line Line22 = new Line(v5, v6);
                    Line Line23 = new Line(v7, new Vector2(v7.X-10,v7.Y));
                    Line23.Layer = dimensioning;
                    dxf.AddEntity(Line23);
                    Line Line24 = new Line(v3, v19);
                    Line24.Layer = dimensioning;
                    dxf.AddEntity(Line24);
                    Line Line25 = new Line(v3, v18);
                    Circle Circle26 = new Circle(v11, dcon / 2);
                    Circle26.Linetype = Linetype.DashDot;
                    Circle26.Layer = refin;
                    dxf.AddEntity(Circle26);
                    Vector2[] Line27 = { v22, v23 };
                    fun.drawPlinetype(dxf, Line27, 0.15, centre, Linetype.Center);
                    //填充
                    LwPolyline hatchpoly1 = new LwPolyline();
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(new Vector2(v1.X, v11.Y)));
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(new Vector2(v2.X, v11.Y)));
                    hatchpoly1.Vertexes[0].Bulge = 1;
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(new Vector2(v1.X, v11.Y)));
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(new Vector2(v2.X, v11.Y)));
                    hatchpoly1.Vertexes[2].Bulge = -1;
                    hatchpoly1.IsClosed = true;
                    String[] htype1 = new String[100];
                    Line[] hline1 = new Line[100];
                    Arc[] harc1 = new Arc[100];
                    int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                    for (int i = 0; i < hnumst1; i++)
                    {
                        htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                        if (htype1[i] == "Line")
                        {
                            hline1[i] = (Line)hatchpoly1.Explode()[i];
                        }
                        if (htype1[i] == "Arc")
                        {
                            harc1[i] = (Arc)hatchpoly1.Explode()[i];
                        }
                    }
                    fun.hatchsub1(dxf, htype1, hnumst1, 45, 5, hline1, harc1, hatching);
                    //标注样式
                    //箭头样式
                    DimensionStyle dimensionStyle = fun.CreateDimStyle();
                    dimensionStyle.ArrowSize = 0.2;
                    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                    //文本样式
                    dimensionStyle.TextHeight = 1.0;
                    double offset = 10;
                    //线段尺寸标注
                    //尺寸1
                    LinearDimension dim1 = new LinearDimension(new Line(v3, v7), offset + (v7.X - v3.X) / 2, 270, dimensionStyle);
                    dim1.UserText = "LH = " + Math.Round(lh / scale, 2);
                    dxf.AddEntity(dim1);
                    //尺寸2
                    LinearDimension dim2 = new LinearDimension(new Line(new Vector2(v11.X, v7.Y), v7), -offset * 2, 0, dimensionStyle);
                    dim2.UserText = "WF = " + Math.Round(wf / scale, 2);
                    dxf.AddEntity(dim2);
                    //尺寸3
                    LinearDimension dim3 = new LinearDimension(new Line(v2, v7), offset * 3 + (v7.X - v2.X) / 2, 270, dimensionStyle);
                    dim3.UserText = "LF = " + Math.Round(lf / scale, 2);
                    dxf.AddEntity(dim3);
                    //尺寸4
                    LinearDimension dim4 = new LinearDimension(new Line(v4, v7), offset * 2 + (v7.X - v4.X) / 2, 270, dimensionStyle);
                    dim4.UserText = "LDRED = " + Math.Round(ldred / scale, 2);
                    dxf.AddEntity(dim4);
                    //尺寸5
                    if (ecd != 0)
                    {
                        LinearDimension dim5 = new LinearDimension(new Line(v5, v6), -offset * 2 - (v5.Y + v6.Y) / 2 + v7.Y, 0, dimensionStyle);
                        dim5.UserText = "ECD = " + Math.Round(ecd / scale, 2);
                        dxf.AddEntity(dim5);
                    }
                    //尺寸6
                    LinearDimension dim6 = new LinearDimension(new Line(v1, v2), offset * 2, 0, dimensionStyle);
                    dim6.UserText = "DCON = Φ" + Math.Round(dcon / scale, 2);
                    dxf.AddEntity(dim6);
                    //尺寸8
                    LinearDimension dim8 = new LinearDimension(new Line(v13, v14), -offset, 0, dimensionStyle);
                    dim8.UserText = "BDRED = Φ" + Math.Round(bdred / scale, 2);
                    dxf.AddEntity(dim8);
                    //尺寸7
                    Angular2LineDimension angdim7 = new Angular2LineDimension(Line24, Line25, offset, dimensionStyle);
                    angdim7.UserText = "HEA = " + Math.Round(hea / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim7);
                    //尺寸11
                    Angular2LineDimension angdim11 = new Angular2LineDimension(Line21, Line23, offset, dimensionStyle);
                    angdim11.UserText = "KAPR = " + Math.Round(kapr / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim11);
                    //尺寸10
                    if (ecd != 0)
                    {
                        Angular2LineDimension angdim10 = new Angular2LineDimension(Line18, Line22, offset, dimensionStyle);
                        angdim10.UserText = "ECA = " + Math.Round(eca / pi * 180, 2) + "°";
                        dxf.AddEntity(angdim10);
                    }
                }
                if (ceatc == "E")//端切
                {
                    double l = ic * (1 + Math.Cos(pi / 3)) / 2 / Math.Cos(pi / 3) / Math.Sin(pi / 3);
                    Vector2 v1 = new Vector2(-dcon/2, 0);
                    Vector2 v2 = new Vector2(dcon/2, 0);
                    Vector2 v3 = new Vector2(bdred/2, -lf + lh);
                    Vector2 v18 = new Vector2(wf - kn_0006, v3.Y - (wf - kn_0006 - bdred/2) / Math.Tan(hea));
                    Vector2 v4 = new Vector2(v2.X, -lf+ldred);
                    Vector2 v7 = new Vector2(wf, -lf);
                    Vector2 v6 = new Vector2(-v18.X+ecd, v7.Y + kn_0004);
                    Vector2 v5 = new Vector2(-v18.X, v6.Y + ecd / Math.Tan(eca));
                    Vector2 v9 = new Vector2(v7.X - l * Math.Sin(pi * 2 / 3 - kapr), v7.Y + l * Math.Cos(pi * 2 / 3 - kapr));
                    Vector2 v8 = new Vector2(v7.X - l * Math.Cos(kapr - pi / 2), v7.Y + l * Math.Sin(kapr - pi / 2));
                    Vector2 v10 = new Vector2(v18.X, v7.Y + (v7.X - v18.X) / Math.Tan(pi * 2 / 3 - kapr));
                    Vector2 v11 = new Vector2(0, -dcon/2 - 5 * scale);
                    Vector2 v12 = new Vector2(-v4.X, v4.Y);
                    Vector2 v13 = new Vector2(-bdred/2, v12.Y-(dcon-bdred)/2);
                    Vector2 v14 = new Vector2(-v13.X, v13.Y);
                    Vector2 v15 = new Vector2(v5.X, v6.Y);
                    Vector2 v16 = new Vector2(v7.X, v7.Y - 10);
                    Vector2 v17 = new Vector2((v6.Y - v8.Y) / Math.Tan(5 * pi / 6 - kapr) + v8.X, v6.Y);
                    Vector2 v19 = new Vector2(v3.X, v18.Y);
                    Vector2 v20 = new Vector2(-v3.X, v3.Y);
                    Vector2 v21 = new Vector2(-v18.X, v18.Y);
                    Vector2 v22 = new Vector2(0, 2);
                    Vector2 v23 = new Vector2(0, v7.Y-2);
                    //线段
                    //主视图
                    Vector2[] Line1 = { v1, v2 };
                    fun.drawBLine(dxf, Line1, 0.3, contour);
                    Vector2[] Line2 = { v2, v4 };
                    fun.drawBLine(dxf, Line2, 0.3, contour);
                    Vector2[] Line7 = { v4, v14 };
                    fun.drawBLine(dxf, Line7, 0.3, contour);
                    Vector2[] Line8 = { v14, v3 };
                    fun.drawBLine(dxf, Line8, 0.3, contour);
                    Vector2[] Line9 = { v3, v18 };
                    fun.drawBLine(dxf, Line9, 0.3, contour);
                    Vector2[] Line10 = { v18, v10 };
                    fun.drawBLine(dxf, Line10, 0.3, contour);
                    Vector2[] Line19 = { v7, v8 };
                    fun.drawBLine(dxf, Line19, 0.3, contour);
                    Vector2[] Line20 = { v8, v9 };
                    fun.drawBLine(dxf, Line20, 0.3, contour);
                    if (ecd != 0)
                    {
                        Vector2[] Line3 = { v21, v5 };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line4 = { v5, v6 };
                        fun.drawBLine(dxf, Line4, 0.3, contour);
                        Vector2[] Line5 = { v6, v17 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    if (ecd == 0)
                    {
                        Vector2[] Line3 = { v21, v15 };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line5 = { v15, v17 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    Vector2[] Line6 = { v7, v9 };
                    fun.drawBLine(dxf, Line6, 0.3, contour);
                    Vector2[] Line11 = { v6, v17 };
                    fun.drawBLine(dxf, Line11, 0.3, contour);
                    Vector2[] Line12 = { v1, v12 };
                    fun.drawBLine(dxf, Line12, 0.3, contour);
                    Vector2[] Line13 = { v12, v13 };
                    fun.drawBLine(dxf, Line13, 0.3, contour);
                    Vector2[] Line14 = { v20, v13 };
                    fun.drawBLine(dxf, Line14, 0.3, contour);
                    Vector2[] Line15 = { v20, v21 };
                    fun.drawBLine(dxf, Line15, 0.3, contour);
                    Vector2[] Line16 = { v12, v4 };
                    fun.drawBLine(dxf, Line16, 0.3, contour);
                    Vector2[] Line17 = { v14, v13 };
                    fun.drawBLine(dxf, Line17, 0.3, contour);
                    Line Line18 = new Line(v5, v15);
                    Line Line21 = new Line(v7, v16);
                    Line18.Layer = dimensioning;
                    Line21.Layer = dimensioning;
                    dxf.AddEntity(Line18);
                    dxf.AddEntity(Line21);
                    Line Line22 = new Line(v5, v6);
                    Line Line23 = new Line(v7, v8);
                    Line Line24 = new Line(v3, v19);
                    Line24.Layer = dimensioning;
                    dxf.AddEntity(Line24);
                    Line Line25 = new Line(v3, v18);
                    Circle Circle26 = new Circle(v11, dcon / 2);
                    Circle26.Linetype = Linetype.DashDot;
                    Circle26.Layer = refin;
                    dxf.AddEntity(Circle26);
                    Vector2[] Line27 = { v22, v23 };
                    fun.drawPlinetype(dxf, Line27, 0.15, centre, Linetype.Center);
                    //填充
                    LwPolyline hatchpoly1 = new LwPolyline();
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(new Vector2(v1.X, v11.Y)));
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(new Vector2(v2.X, v11.Y)));
                    hatchpoly1.Vertexes[0].Bulge = 1;
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(new Vector2(v1.X, v11.Y)));
                    hatchpoly1.Vertexes.Add(new LwPolylineVertex(new Vector2(v2.X, v11.Y)));
                    hatchpoly1.Vertexes[2].Bulge = -1;
                    hatchpoly1.IsClosed = true;
                    String[] htype1 = new String[100];
                    Line[] hline1 = new Line[100];
                    Arc[] harc1 = new Arc[100];
                    int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                    for (int i = 0; i < hnumst1; i++)
                    {
                        htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                        if (htype1[i] == "Line")
                        {
                            hline1[i] = (Line)hatchpoly1.Explode()[i];
                        }
                        if (htype1[i] == "Arc")
                        {
                            harc1[i] = (Arc)hatchpoly1.Explode()[i];
                        }
                    }
                    fun.hatchsub1(dxf, htype1, hnumst1, 45, 5, hline1, harc1, hatching);
                    //标注样式
                    //箭头样式
                    DimensionStyle dimensionStyle = fun.CreateDimStyle();
                    dimensionStyle.ArrowSize = 0.2;
                    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                    //文本样式
                    dimensionStyle.TextHeight = 1.0;
                    double offset = 10;
                    //线段尺寸标注
                    //尺寸1
                        LinearDimension dim1 = new LinearDimension(new Line(v3, v7), offset + (v7.X-v3.X) / 2, 270, dimensionStyle);
                        dim1.UserText = "LH = " + Math.Round(lh / scale, 2);
                        dxf.AddEntity(dim1);
                    //尺寸2
                    LinearDimension dim2 = new LinearDimension(new Line(new Vector2(v11.X,v7.Y), v7), -offset * 2, 0, dimensionStyle);
                    dim2.UserText = "WF = " + Math.Round(wf / scale, 2);
                    dxf.AddEntity(dim2);
                    //尺寸3
                    LinearDimension dim3 = new LinearDimension(new Line(v2, v7), offset*3 + (v7.X - v2.X) / 2, 270, dimensionStyle);
                    dim3.UserText = "LF = " + Math.Round(lf / scale, 2);
                    dxf.AddEntity(dim3);
                    //尺寸4
                    LinearDimension dim4 = new LinearDimension(new Line(v4, v7), offset * 2 + (v7.X - v4.X) / 2, 270, dimensionStyle);
                    dim4.UserText = "LDRED = " + Math.Round(ldred / scale, 2);
                    dxf.AddEntity(dim4);
                    //尺寸5
                    if (ecd != 0)
                    {
                        LinearDimension dim5 = new LinearDimension(new Line(v5, v6), -offset*2 - (v5.Y + v6.Y) / 2 + v7.Y, 0, dimensionStyle);
                        dim5.UserText = "ECD = " + Math.Round(ecd / scale, 2);
                        dxf.AddEntity(dim5);
                    }
                    //尺寸6
                    LinearDimension dim6 = new LinearDimension(new Line(v1, v2), offset*2, 0, dimensionStyle);
                    dim6.UserText = "DCON = Φ" + Math.Round(dcon / scale, 2);
                    dxf.AddEntity(dim6);
                    //尺寸8
                    LinearDimension dim8 = new LinearDimension(new Line(v13, v14), -offset, 0, dimensionStyle);
                    dim8.UserText = "BDRED = Φ" + Math.Round(bdred / scale, 2);
                    dxf.AddEntity(dim8);
                    //尺寸7
                    Angular2LineDimension angdim7 = new Angular2LineDimension(Line24, Line25, offset, dimensionStyle);
                    angdim7.UserText = "HEA = " + Math.Round(hea / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim7);
                    //尺寸11
                    Angular2LineDimension angdim11 = new Angular2LineDimension(Line21, Line23, offset, dimensionStyle);
                    angdim11.UserText = "KAPR = " + Math.Round(kapr / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim11);
                    //尺寸10
                    if (ecd != 0)
                    {
                        Angular2LineDimension angdim10 = new Angular2LineDimension(Line18, Line22, offset, dimensionStyle);
                        angdim10.UserText = "ECA = " + Math.Round(eca / pi * 180, 2) + "°";
                        dxf.AddEntity(angdim10);
                    }
                }
            //图框
            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA3Y(dxf, new Vector2(-148.5 + dcon / 2, 210 - lf / 2));
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void TurningToolForODGroovingAndParting(Dictionary<string, Object> data)  //8.外切槽和切断车刀
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour");//轮廓层
            Layer dimensioning = new Layer("dimensioning");//尺寸层
            Layer refin = new Layer("refin");//基准线/内轮廓/虚线
            Layer center = new Layer("center");//中心线
            Layer textlayer = new Layer("textlayer");//文本层
            Layer hatching = new Layer("hatching");//填充层
            Layer additionalline = new Layer("additionalline");//附加线
            Layer cutting = new Layer("cutting");//切削层
            dxf.Layers["0"].Lineweight = Lineweight.W25;

            //参数
            string path = Convert.ToString(data["path"]);
            double slf = Convert.ToDouble(data["lf"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0)
            {
                if (slf < 67)
                {
                    scale = 4.0;
                }
                else if (slf < 90)
                {
                    scale = 3.0;
                }
                else if (slf < 134)
                {
                    scale = 2.0;
                }
                else if (slf < 178)
                {
                    scale = 1.5;
                }
                else if (slf < 268)
                {
                    scale = 1.0;
                }
                else if (slf < 357)
                {
                    scale = 0.75;
                }
                else
                {
                    scale = 0.5;
                }
            }
            double pi = Math.PI;
            double lf = Convert.ToDouble(data["lf"]) * scale;
            double lh = Convert.ToDouble(data["lh"]) * scale;
            double b = Convert.ToDouble(data["b"]) * scale;
            double h = Convert.ToDouble(data["h"]) * scale;
            double wf = Convert.ToDouble(data["wf"]) * scale;
            double cwx = Convert.ToDouble(data["cwx"]) * scale;
            double ecd = Convert.ToDouble(data["ecd"]) * scale;
            double kapr = Convert.ToDouble(data["kapr"]) * pi / 180;
            double eca = Convert.ToDouble(data["eca"]) * pi / 180;
            double cdx = Convert.ToDouble(data["cdx"]) * scale;
            double isframe = Convert.ToDouble(data["isframe"]);
            //坐标
            //主视图
            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(b, 0);
            Vector2 v3 = new Vector2(v2.X, -lf + lh);
            Vector2 v4 = new Vector2(0, v3.Y);
            Vector2 v5 = new Vector2(0, -lf + cdx + ecd / Math.Tan(eca));
            Vector2 v6 = new Vector2(ecd, -lf+cdx);
            Vector2 v7 = new Vector2(v2.X, v6.Y);
            Vector2 v8 = new Vector2(wf*2 - b, v7.Y);
            Vector2 v9 = new Vector2(wf-cwx/2, -lf);
            Vector2 v10 = new Vector2(wf+cwx/2, -lf);
            Vector2 v11 = new Vector2(v2.X, -h - 5 * scale);
            Vector2 v12 = new Vector2(0, v11.Y);
            Vector2 v13 = new Vector2(0, -5 * scale);
            Vector2 v14 = new Vector2(v11.X, v13.Y);
            Vector2 v15 = new Vector2(wf, v8.Y+2);
            Vector2 v16 = new Vector2(v15.X, v10.Y - 2);
            //线段
            //主视图
            Vector2[] Line1 = { v1, v2 };
            fun.drawBLine(dxf, Line1, 0.3, contour);
            Vector2[] Line2 = { v2, v7 };
            fun.drawBLine(dxf, Line2, 0.3, contour);
            Vector2[] Line19 = { v7, v10 };
            fun.drawBLine(dxf, Line19, 0.3, contour);
            Vector2[] Line20 = { v10, v9 };
            fun.drawBLine(dxf, Line20, 0.3, contour);
            if (ecd != 0)
            {
                Vector2[] Line3 = { v1, v5 };
                fun.drawBLine(dxf, Line3, 0.3, contour);
                Vector2[] Line4 = { v5, v6 };
                fun.drawBLine(dxf, Line4, 0.3, contour);
                Vector2[] Line5 = { v6, v7 };
                fun.drawBLine(dxf, Line5, 0.3, contour);
            }
            if (ecd == 0)
            {
                Vector2[] Line3 = { v1, new Vector2(v5.X,v6.Y) };
                fun.drawBLine(dxf, Line3, 0.3, contour);
                Vector2[] Line5 = { new Vector2(v5.X, v6.Y), v7 };
                fun.drawBLine(dxf, Line5, 0.3, contour);
            }
            Vector2[] Line6 = { v8, v9 };
            fun.drawBLine(dxf, Line6, 0.3, contour);
            if (lh != 0)
            {
                Vector2[] Line9 = { v3, v4 };
                fun.drawBLine(dxf, Line9, 0.3, contour);
            }
            Vector2[] Line10 = { v11, v12 };
            fun.drawPlinetype(dxf, Line10, 0.15, refin, Linetype.DashDot);
            Vector2[] Line11 = { v13, v14 };
            fun.drawPlinetype(dxf, Line11, 0.15, refin, Linetype.DashDot);
            Line Line12 = new Line(v11, v12);
            Line Line13 = new Line(v13, v14);
            Line Line14 = new Line(v5, new Vector2(v5.X, v6.Y));
            Line Line15 = new Line(new Vector2(v16.X, v10.Y), new Vector2(v16.X, v10.Y-5));
            Line14.Layer = dimensioning;
            Line15.Layer = dimensioning;
            dxf.AddEntity(Line14);
            dxf.AddEntity(Line15);
            Line Line16 = new Line(v5, v6);
            Line Line17 = new Line(v7, v8);
            Line Line18 = new Line(new Vector2(v16.X, v10.Y), new Vector2(v16.X+5, v10.Y));
            Line18.Layer = dimensioning;
            dxf.AddEntity(Line18);
            Vector2[] Line21 = { v15, v16 };
            fun.drawPlinetype(dxf, Line21, 0.15, center, Linetype.Center);
            //填充
            LwPolyline hatchpoly3 = new LwPolyline();
            hatchpoly3.Vertexes.Add(new LwPolylineVertex(v11));
            hatchpoly3.Vertexes.Add(new LwPolylineVertex(v12));
            hatchpoly3.Vertexes.Add(new LwPolylineVertex(v13));
            hatchpoly3.Vertexes.Add(new LwPolylineVertex(v14));
            hatchpoly3.IsClosed = true;
            String[] htype3 = new String[100];
            Line[] hline3 = new Line[100];
            int hnumst3 = hatchpoly3.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst3; i++)
            {
                htype3[i] = hatchpoly3.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (htype3[i] == "Line")
                {
                    hline3[i] = (Line)hatchpoly3.Explode()[i];
                }
            }
            fun.hatchsubofline(dxf, htype3, hnumst3, 45, 5, hline3, hatching);
            //标注样式
            //箭头样式
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 3.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            //文本样式
            dimensionStyle.TextHeight = 3.5;
            double offset = 10;
            //线段尺寸标注
            //尺寸1
            if (lh != 0)
            {
                LinearDimension dim1 = new LinearDimension(new Line(v4, v9), -offset*2 - v9.X / 2, 270, dimensionStyle);
                dim1.UserText = "LH = " + Math.Round(lh / scale, 2);
                dxf.AddEntity(dim1);
            }
            //尺寸2
            LinearDimension dim2 = new LinearDimension(new Line(v12, v16), -offset * 2 - (v12.Y - v16.Y) / 2, 0, dimensionStyle);
            dim2.UserText = "WF = " + Math.Round(wf / scale, 2);
            dxf.AddEntity(dim2);
            //尺寸3
            LinearDimension dim3 = new LinearDimension(new Line(v2, v10), offset + (v10.X - v2.X) / 2, 270, dimensionStyle);
            dim3.UserText = "LF = " + Math.Round(lf / scale, 2);
            dxf.AddEntity(dim3);
            //尺寸5
            if (ecd != 0)
            {
                LinearDimension dim5 = new LinearDimension(new Line(v5, v6), -offset - (v5.Y + v6.Y) / 2 + v9.Y, 0, dimensionStyle);
                dim5.UserText = "ECD = " + Math.Round(ecd / scale, 2);
                dxf.AddEntity(dim5);
            }
            //尺寸6
            LinearDimension dim6 = new LinearDimension(new Line(v1, v2), offset, 0, dimensionStyle);
            dim6.UserText = "B = " + Math.Round(b / scale, 2);
            dxf.AddEntity(dim6);
            //尺寸11
            Angular2LineDimension angdim11 = new Angular2LineDimension(Line18, Line15, offset*3, dimensionStyle);
            angdim11.UserText = "KAPR = " + Math.Round(kapr / pi * 180, 2) + "°";
            dxf.AddEntity(angdim11);
            //尺寸10
            if (ecd != 0)
            {
                Angular2LineDimension angdim10 = new Angular2LineDimension(Line16, Line14, offset, dimensionStyle);
                angdim10.UserText = "ECA = " + Math.Round(eca / pi * 180, 2) + "°";
                dxf.AddEntity(angdim10);
            }
            //尺寸12
            LinearDimension dim12 = new LinearDimension(new Line(v12, v13), -offset, 270, dimensionStyle);
            dim12.UserText = "H = " + Math.Round(h / scale, 2);
            dxf.AddEntity(dim12);
            //尺寸13
            LinearDimension dim13 = new LinearDimension(new Line(v9, v10), -offset, 0, dimensionStyle);
            dim13.UserText = "CWX = " + Math.Round(cwx / scale, 2);
            dxf.AddEntity(dim13);
            //尺寸14
            LinearDimension dim14 = new LinearDimension(new Line(v6, v9), -offset-(v6.X+v9.X)/2, 270, dimensionStyle);
            dim14.UserText = "CDX = " + Math.Round(cdx / scale, 2);
            dxf.AddEntity(dim14);
            //图框
            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA3Y(dxf, new Vector2(-148.5 + b / 2, 210 - lf / 2));
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }
            fun.SetLayer(dxf);
            fun.SetByLayer(dxf);
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void BoringBarForIDGrooving(Dictionary<string, Object> data)  //9.内切槽镗杆
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
            //作图
            //参数
            string path = Convert.ToString(data["path"]);
            double soal = Convert.ToDouble(data["oal"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0)
            {
                if (soal < 67)
                {
                    scale = 4.0;
                }
                else if (soal < 90)
                {
                    scale = 3.0;
                }
                else if (soal < 134)
                {
                    scale = 2.0;
                }
                else if (soal < 178)
                {
                    scale = 1.5;
                }
                else if (soal < 268)
                {
                    scale = 1.0;
                }
                else if (soal < 357)
                {
                    scale = 0.75;
                }
                else
                {
                    scale = 0.5;
                }
            }
            double pi = Math.PI;
            double oal = Convert.ToDouble(data["oal"]) * scale;
            double lh = Convert.ToDouble(data["lh"]) * scale;
            double dcon = Convert.ToDouble(data["dcon"]) * scale;
            double bdred = Convert.ToDouble(data["bdred"]) * scale;
            double ldred = Convert.ToDouble(data["ldred"]) * scale;
            double wf = Convert.ToDouble(data["wf"]) * scale;
            double cwx = Convert.ToDouble(data["cwx"]) * scale;
            double cwn = Convert.ToDouble(data["cwn"]) * scale;
            double ecd = Convert.ToDouble(data["ecd"]) * scale;
            double kapr = Convert.ToDouble(data["kapr"]) * pi / 180;
            double eca = Convert.ToDouble(data["eca"]) * pi / 180;
            double cdx = wf - dcon / 2;
            double lf = oal - cwx / 2;
            double isframe = Convert.ToDouble(data["isframe"]);
            //坐标
            //主视图
            Vector2 v1 = new Vector2(-dcon/2, 0);
            Vector2 v2 = new Vector2(-v1.X, v1.Y);
            Vector2 v3 = new Vector2(bdred/2, -oal + lh);
            Vector2 v4 = new Vector2(-v3.X, v3.Y);
            Vector2 v5 = new Vector2(v4.X, -oal + cwx / 2 - cwn / 2 + ecd / Math.Tan(eca));
            Vector2 v6 = new Vector2(v5.X+ecd, -oal + cwx/2-cwn/2);
            Vector2 v7 = new Vector2(v3.X, v6.Y);
            Vector2 v8 = new Vector2(v7.X, v7.Y+cwn);
            Vector2 v9 = new Vector2(wf, v7.Y+cwn/2+cwx/2);
            Vector2 v10 = new Vector2(v9.X, v9.Y-cwx);
            Vector2 v11 = new Vector2(0, -dcon/2 - 5 * scale);
            Vector2 v12 = new Vector2(v1.X, -oal + ldred);
            Vector2 v13 = new Vector2(-v12.X, v12.Y);
            Vector2 v14 = new Vector2(v7.X, v13.Y - v13.X + v7.X);
            Vector2 v17 = new Vector2(-v14.X, v14.Y);
            Vector2 v15 = new Vector2(v7.X - 2, v7.Y + cwn / 2);
            Vector2 v16 = new Vector2(v10.X + 2, v15.Y);
            Vector2 v18 = new Vector2(v5.X, v6.Y);
            Vector2 v19 = new Vector2(v10.X+10, v10.Y);
            Vector2 v20 = new Vector2(v10.X, v10.Y-10);
            Vector2 v21 = new Vector2(0, 2);
            Vector2 v22 = new Vector2(0, -oal-2);
            //线段
            //主视图
            Vector2[] Line1 = { v1, v2 };
            fun.drawBLine(dxf, Line1, 0.3, contour);
            Vector2[] Line2 = { v2, v13 };
            fun.drawBLine(dxf, Line2, 0.3, contour);
            Vector2[] Line19 = { v13, v14 };
            fun.drawBLine(dxf, Line19, 0.3, contour);
            Vector2[] Line20 = { v14, v7 };
            fun.drawBLine(dxf, Line20, 0.3, contour);
            if (ecd != 0)
            {
                Vector2[] Line3 = { v17, v5 };
                fun.drawBLine(dxf, Line3, 0.3, contour);
                Vector2[] Line4 = { v5, v6 };
                fun.drawBLine(dxf, Line4, 0.3, contour);
                Vector2[] Line5 = { v6, v7 };
                fun.drawBLine(dxf, Line5, 0.3, contour);
            }
            if (ecd == 0)
            {
                Vector2[] Line3 = { v17, v18 };
                fun.drawBLine(dxf, Line3, 0.3, contour);
                Vector2[] Line5 = { v18, v7 };
                fun.drawBLine(dxf, Line5, 0.3, contour);
            }
            Vector2[] Line6 = { v12, v17 };
            fun.drawBLine(dxf, Line6, 0.3, contour);
            if (lh != 0)
            {
                Vector2[] Line9 = { v3, v4 };
                fun.drawBLine(dxf, Line9, 0.3, contour);
            }
            Vector2[] Line7 = { v12, v1 };
            fun.drawBLine(dxf, Line7, 0.3, contour);
            Vector2[] Line8 = { v12, v13 };
            fun.drawBLine(dxf, Line8, 0.3, contour);
            Vector2[] Line10 = { v14, v17 };
            fun.drawBLine(dxf, Line10, 0.3, contour);
            Vector2[] Line11 = { v8, v9 };
            fun.drawBLine(dxf, Line11, 0.3, contour);
            Vector2[] Line12 = { v9, v10 };
            fun.drawBLine(dxf, Line12, 0.3, contour);
            Vector2[] Line13 = { v10, v7 };
            fun.drawBLine(dxf, Line13, 0.3, contour);
            Line Line14 = new Line(v5, v18);
            Line Line15 = new Line(v10, v19);
            Line Line16 = new Line(v5, v6);
            Line Line17 = new Line(v10, v20);
            Line14.Layer = dimensioning;
            Line15.Layer = dimensioning;
            Line17.Layer = dimensioning;
            dxf.AddEntity(Line14);
            dxf.AddEntity(Line17);
            dxf.AddEntity(Line15);
            Vector2[] Line18 = { v21, v22 };
            fun.drawPlinetype(dxf, Line18, 0.15, centre, Linetype.Center);
            Circle Circle19 = new Circle(v11, dcon / 2);
            Circle19.Linetype = Linetype.DashDot;
            Circle19.Layer = refin;
            dxf.AddEntity(Circle19);
            //填充
            LwPolyline hatchpoly1 = new LwPolyline();
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(new Vector2(v1.X, v11.Y)));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(new Vector2(v2.X, v11.Y)));
            hatchpoly1.Vertexes[0].Bulge = 1;
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(new Vector2(v1.X, v11.Y)));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(new Vector2(v2.X, v11.Y)));
            hatchpoly1.Vertexes[2].Bulge = -1;
            hatchpoly1.IsClosed = true;
            String[] htype1 = new String[100];
            Line[] hline1 = new Line[100];
            Arc[] harc1 = new Arc[100];
            int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)hatchpoly1.Explode()[i];
                }
                if (htype1[i] == "Arc")
                {
                    harc1[i] = (Arc)hatchpoly1.Explode()[i];
                }
            }
            fun.hatchsub1(dxf, htype1, hnumst1, 45, 5, hline1, harc1, hatching);
            //标注样式
            //箭头样式
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 3.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            //文本样式
            dimensionStyle.TextHeight = 3.5;
            double offset = 10;
            //线段尺寸标注
            //尺寸1
            if (lh != 0)
            {
                LinearDimension dim1 = new LinearDimension(new Line(v4, v10), -offset - (v10.X-v4.X) / 2, 270, dimensionStyle);
                dim1.UserText = "LH = " + Math.Round(lh / scale, 2);
                dxf.AddEntity(dim1);
            }
            //尺寸2
            LinearDimension dim2 = new LinearDimension(new Line(v22, v10), -offset * 2 - (v10.Y - v22.Y) / 2, 0, dimensionStyle);
            dim2.UserText = "WF = " + Math.Round(wf / scale, 2);
            dxf.AddEntity(dim2);
            //尺寸3
            LinearDimension dim3 = new LinearDimension(new Line(new Vector2(v9.X,v16.Y), v2), offset + (v9.X - v2.X) / 2, 270, dimensionStyle);
            dim3.UserText = "LF = " + Math.Round(lf / scale, 2);
            dxf.AddEntity(dim3);
            //尺寸5
            if (ecd != 0)
            {
                LinearDimension dim5 = new LinearDimension(new Line(v5, v6), -offset*2 - (v5.Y + v6.Y) / 2 + v10.Y, 0, dimensionStyle);
                dim5.UserText = "ECD = " + Math.Round(ecd / scale, 2);
                dxf.AddEntity(dim5);
            }
            //尺寸6
            LinearDimension dim6 = new LinearDimension(new Line(v1, v2), offset, 0, dimensionStyle);
            dim6.UserText = "DCON = Φ" + Math.Round(dcon / scale, 2);
            dxf.AddEntity(dim6);
            //尺寸11
            Angular2LineDimension angdim11 = new Angular2LineDimension(Line17, Line15, offset * 2, dimensionStyle);
            angdim11.UserText = "KAPR = " + Math.Round(kapr / pi * 180, 2) + "°";
            dxf.AddEntity(angdim11);
            //尺寸10
            if (ecd != 0)
            {
                Angular2LineDimension angdim10 = new Angular2LineDimension(Line16, Line14, offset, dimensionStyle);
                angdim10.UserText = "ECA = " + Math.Round(eca / pi * 180, 2) + "°";
                dxf.AddEntity(angdim10);
            }
            //尺寸13
            LinearDimension dim13 = new LinearDimension(new Line(v9, v10), offset*2, 270, dimensionStyle);
            dim13.UserText = "CW = " + Math.Round(cwx / scale, 2);
            dxf.AddEntity(dim13);
            //尺寸14
            LinearDimension dim14 = new LinearDimension(new Line(v8, v9), offset + (v9.Y - v8.Y) / 2, 0, dimensionStyle);
            dim14.UserText = "CDX = " + Math.Round(cdx / scale, 2);
            dxf.AddEntity(dim14);
            //尺寸12
            LinearDimension dim12 = new LinearDimension(new Line(v10, v2), offset*3 + (v9.X - v2.X) / 2, 270, dimensionStyle);
            dim12.UserText = "OAL = " + Math.Round(oal / scale, 2);
            dxf.AddEntity(dim12);
            //图框
            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA3Y(dxf, new Vector2(-148.5, 210 - lf / 2));
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void PullBackBoringBar(Dictionary<string, Object> data)  //10.背镗杆
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
            //作图
            //参数
            string path = Convert.ToString(data["path"]);
            double soal = Convert.ToDouble(data["oal"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0)
            {
                if (soal < 67)
                {
                    scale = 4.0;
                }
                else if (soal < 90)
                {
                    scale = 3.0;
                }
                else if (soal < 134)
                {
                    scale = 2.0;
                }
                else if (soal < 178)
                {
                    scale = 1.5;
                }
                else if (soal < 268)
                {
                    scale = 1.0;
                }
                else if (soal < 357)
                {
                    scale = 0.75;
                }
                else
                {
                    scale = 0.5;
                }
            }
            double pi = Math.PI;
            double oal = Convert.ToDouble(data["oal"]) * scale;
            double lf = Convert.ToDouble(data["lf"]) * scale;
            double lh = oal - lf;
            double dcon = Convert.ToDouble(data["dcon"]) * scale;
            double bdred = Convert.ToDouble(data["bdred"]) * scale;
            double ldred = Convert.ToDouble(data["ldred"]) * scale;
            double wf = Convert.ToDouble(data["wf"]) * scale;
            double ic = Convert.ToDouble(data["ic"]) * scale;
            double ecd = Convert.ToDouble(data["ecd"]) * scale;
            double kapr = Convert.ToDouble(data["kapr"]) * pi / 180;
            double eca = Convert.ToDouble(data["eca"]) * pi / 180;
            double epsr = Convert.ToDouble(data["epsr"]) * pi / 180;
            double kn0001 = Convert.ToDouble(data["kn0001"]) * scale;
            double kn0002 = Convert.ToDouble(data["kn0002"]) * scale;
            double isframe = Convert.ToDouble(data["isframe"]);
            //坐标
            //主视图
            double l = ic / 2 / Math.Cos(epsr / 2) / Math.Sin(epsr / 2);
            Vector2 v1 = new Vector2(-dcon / 2, 0);
            Vector2 v2 = new Vector2(-v1.X, v1.Y);
            Vector2 v3 = new Vector2(wf, -lf);
            Vector2 v4 = new Vector2(v3.X - l * Math.Cos(kapr - pi / 2), v3.Y - l * Math.Sin(kapr - pi / 2));
            Vector2 v5 = new Vector2(-bdred/2, -oal + ecd / Math.Tan(eca));
            Vector2 v6 = new Vector2(v5.X + ecd, -oal);
            Vector2 v15 = new Vector2(v3.X - l * Math.Sin(pi - kapr - epsr), v3.Y - l * Math.Cos(pi - kapr - epsr));
            Vector2 v10 = new Vector2(v15.X- l * Math.Cos(kapr - pi / 2), v15.Y - l * Math.Sin(kapr - pi / 2));
            Vector2 v16 = new Vector2(v15.X-kn0002/Math.Sin(epsr)*Math.Cos(kapr-pi/2), v15.Y - kn0002 / Math.Sin(epsr) * Math.Sin(kapr - pi / 2));
            Vector2 v9 = new Vector2(v4.X- kn0001 / Math.Sin(epsr) * Math.Sin(pi-kapr - epsr), v4.Y - kn0001 / Math.Sin(epsr) * Math.Cos(pi - kapr - epsr));
            Vector2 v7 = new Vector2(v16.X - (v16.Y + oal) * Math.Tan(pi - kapr - epsr), v6.Y);
            Vector2 v8 = new Vector2(bdred / 2, v9.Y - (v9.X - bdred / 2) * Math.Tan(kapr - pi / 2));
            Vector2 v11 = new Vector2(0, -dcon / 2 - 5 * scale);
            Vector2 v12 = new Vector2(v1.X, -lf + ldred);
            Vector2 v13 = new Vector2(-v12.X, v12.Y);
            Vector2 v14 = new Vector2(v8.X, v13.Y - v13.X + v8.X);
            Vector2 v17 = new Vector2(-v14.X, v14.Y);
            Vector2 v18 = new Vector2(v5.X, v6.Y);
            Vector2 v19 = new Vector2(v3.X, v3.Y+v3.X-v4.X);
            Vector2 v20 = new Vector2(0, 2);
            Vector2 v21 = new Vector2(0, -oal - 2);
            //线段
            //主视图
            Vector2[] Line1 = { v1, v2 };
            fun.drawBLine(dxf, Line1, 0.3, contour);
            Vector2[] Line2 = { v2, v13 };
            fun.drawBLine(dxf, Line2, 0.3, contour);
            Vector2[] Line19 = { v13, v14 };
            fun.drawBLine(dxf, Line19, 0.3, contour);
            Vector2[] Line20 = { v14, v8 };
            fun.drawBLine(dxf, Line20, 0.3, contour);
            if (ecd != 0)
            {
                Vector2[] Line3 = { v17, v5 };
                fun.drawBLine(dxf, Line3, 0.3, contour);
                Vector2[] Line4 = { v5, v6 };
                fun.drawBLine(dxf, Line4, 0.3, contour);
                Vector2[] Line5 = { v6, v7 };
                fun.drawBLine(dxf, Line5, 0.3, contour);
            }
            if (ecd == 0)
            {
                Vector2[] Line3 = { v17, v18 };
                fun.drawBLine(dxf, Line3, 0.3, contour);
                Vector2[] Line5 = { v18, v7 };
                fun.drawBLine(dxf, Line5, 0.3, contour);
            }
            Vector2[] Line6 = { v12, v17 };
            fun.drawBLine(dxf, Line6, 0.3, contour);
            Vector2[] Line9 = { v3, v4 };
            fun.drawBLine(dxf, Line9, 0.3, contour);
            Vector2[] Line7 = { v12, v1 };
            fun.drawBLine(dxf, Line7, 0.3, contour);
            Vector2[] Line8 = { v12, v13 };
            fun.drawBLine(dxf, Line8, 0.3, contour);
            Vector2[] Line10 = { v14, v17 };
            fun.drawBLine(dxf, Line10, 0.3, contour);
            Vector2[] Line11 = { v8, v9 };
            fun.drawBLine(dxf, Line11, 0.3, contour);
            Vector2[] Line12 = { v4, v10 };
            fun.drawBLine(dxf, Line12, 0.3, contour);
            Vector2[] Line13 = { v10, v15 };
            fun.drawBLine(dxf, Line13, 0.3, contour);
            Vector2[] Line21 = { v15, v3 };
            fun.drawBLine(dxf, Line21, 0.3, contour);
            Vector2[] Line22 = { v16, v7 };
            fun.drawBLine(dxf, Line22, 0.3, contour);
            Line Line14 = new Line(v5, v18);
            Line Line15 = new Line(v3, v19);
            Line Line16 = new Line(v5, v6);
            Line Line17 = new Line(v3, v4);
            Line14.Layer = dimensioning;
            Line15.Layer = dimensioning;
            dxf.AddEntity(Line14);
            dxf.AddEntity(Line15);
            Line Line23 = new Line(v3, v15);
            Vector2[] Line18 = { v21, v20 };
            fun.drawPlinetype(dxf, Line18, 0.15, centre, Linetype.Center);
            Circle Circle19 = new Circle(v11, dcon / 2);
            Circle19.Linetype = Linetype.DashDot;
            Circle19.Layer = refin;
            dxf.AddEntity(Circle19);
            //填充
            LwPolyline hatchpoly1 = new LwPolyline();
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(new Vector2(v1.X, v11.Y)));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(new Vector2(v2.X, v11.Y)));
            hatchpoly1.Vertexes[0].Bulge = 1;
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(new Vector2(v1.X, v11.Y)));
            hatchpoly1.Vertexes.Add(new LwPolylineVertex(new Vector2(v2.X, v11.Y)));
            hatchpoly1.Vertexes[2].Bulge = -1;
            hatchpoly1.IsClosed = true;
            String[] htype1 = new String[100];
            Line[] hline1 = new Line[100];
            Arc[] harc1 = new Arc[100];
            int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
            for (int i = 0; i < hnumst1; i++)
            {
                htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                if (htype1[i] == "Line")
                {
                    hline1[i] = (Line)hatchpoly1.Explode()[i];
                }
                if (htype1[i] == "Arc")
                {
                    harc1[i] = (Arc)hatchpoly1.Explode()[i];
                }
            }
            fun.hatchsub1(dxf, htype1, hnumst1, 45, 5, hline1, harc1, hatching);
            //标注样式
            //箭头样式
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 3.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            //文本样式
            dimensionStyle.TextHeight = 3.5;
            double offset = 10;
            //线段尺寸标注
            //尺寸1
            LinearDimension dim1 = new LinearDimension(new Line(v3, v7), offset + (v3.X - v7.X) / 2, 270, dimensionStyle);
            dim1.UserText = "LH = " + Math.Round(lh / scale, 2);
            dxf.AddEntity(dim1);
            //尺寸2
            LinearDimension dim2 = new LinearDimension(new Line(v21, v3), -offset * 2 - (v3.Y - v21.Y) / 2+2, 0, dimensionStyle);
            dim2.UserText = "WF = " + Math.Round(wf / scale, 2);
            dxf.AddEntity(dim2);
            //尺寸3
            LinearDimension dim3 = new LinearDimension(new Line(v3, v2), offset*2 + (v3.X - v2.X) / 2, 270, dimensionStyle);
            dim3.UserText = "LF = " + Math.Round(lf / scale, 2);
            dxf.AddEntity(dim3);
            //尺寸4
            LinearDimension dim4 = new LinearDimension(new Line(v17, v14), -offset, 0, dimensionStyle);
            dim4.UserText = "BDRED = Φ" + Math.Round(bdred / scale, 2);
            dxf.AddEntity(dim4);
            //尺寸5
            if (ecd != 0)
            {
                LinearDimension dim5 = new LinearDimension(new Line(v5, v6), -offset * 2 - (v5.Y - v6.Y) / 2, 0, dimensionStyle);
                dim5.UserText = "ECD = " + Math.Round(ecd / scale, 2);
                dxf.AddEntity(dim5);
            }
            //尺寸6
            LinearDimension dim6 = new LinearDimension(new Line(v1, v2), offset, 0, dimensionStyle);
            dim6.UserText = "DCON = Φ" + Math.Round(dcon / scale, 2);
            dxf.AddEntity(dim6);
            //尺寸11
            Angular2LineDimension angdim11 = new Angular2LineDimension(Line17, Line15, offset * 2, dimensionStyle);
            angdim11.UserText = "KAPR = " + Math.Round(kapr / pi * 180, 2) + "°";
            dxf.AddEntity(angdim11);
            //尺寸10
            if (ecd != 0)
            {
                Angular2LineDimension angdim10 = new Angular2LineDimension(Line16, Line14, offset, dimensionStyle);
                angdim10.UserText = "ECA = " + Math.Round(eca / pi * 180, 2) + "°";
                dxf.AddEntity(angdim10);
            }
            //尺寸13
            LinearDimension dim13 = new LinearDimension(new Line(v3, v13), offset+(v3.X-v13.X)/2, 270, dimensionStyle);
            dim13.UserText = "LDRED = " + Math.Round(ldred / scale, 2);
            dxf.AddEntity(dim13);
            //尺寸14
            LinearDimension dim14 = new LinearDimension(new Line(v3, v4), offset, (kapr-pi/2)/pi*180, dimensionStyle);
            dim14.UserText = "L = " + Math.Round(l / scale, 2);
            dxf.AddEntity(dim14);
            //尺寸12
            LinearDimension dim12 = new LinearDimension(new Line(v7, v2), offset * 3 +v3.X- (v7.X + v2.X) / 2, 270, dimensionStyle);
            dim12.UserText = "OAL = " + Math.Round(oal / scale, 2);
            dxf.AddEntity(dim12);
            //图框
            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA3Y(dxf, new Vector2(-148.5, 210 - lf / 2));
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void SystemToolForExternalTurning(Dictionary<string, Object> data) //11.外圆车削工具系统
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
            //作图
            //参数
            string path = Convert.ToString(data["path"]);
            double slf = Convert.ToDouble(data["lf"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0)
            {
                if (slf < 33.5)
                {
                    scale = 4.0;
                }
                else if (slf < 45)
                {
                    scale = 3.0;
                }
                else if (slf < 67)
                {
                    scale = 2.0;
                }
                else if (slf < 89)
                {
                    scale = 1.5;
                }
                else if (slf < 134)
                {
                    scale = 1.0;
                }
                else if (slf < 179)
                {
                    scale = 0.75;
                }
                else
                {
                    scale = 0.5;
                }
            }
            double pi = Math.PI;
            double lf = Convert.ToDouble(data["lf"]) * scale;
            double bdred = Convert.ToDouble(data["bdred"]) * scale;
            double lh = Convert.ToDouble(data["lh"]) * scale;
            double dcon = Convert.ToDouble(data["dcon"]) * scale;
            double ldred = Convert.ToDouble(data["ldred"]) * scale;
            double wf = Convert.ToDouble(data["wf"]) * scale;
            double ic = Convert.ToDouble(data["ic"]) * scale;
            double ecd = Convert.ToDouble(data["ecd"]) * scale;
            double kapr = Convert.ToDouble(data["kapr"]) * pi / 180;
            double eca = Convert.ToDouble(data["eca"]) * pi / 180;
            double hea = Convert.ToDouble(data["hea"]) * pi / 180;
            double epsr = Convert.ToDouble(data["epsr"]) * pi / 180;
            double kn0001 = Convert.ToDouble(data["kn0001"]) * scale;
            double kn0002 = Convert.ToDouble(data["kn0002"]) * scale;
            string thsc = Convert.ToString(data["thsc"]);
            string ceatc = Convert.ToString(data["ceatc"]);
            double isframe = Convert.ToDouble(data["isframe"]);
            //坐标
            //主视图
            if (thsc == "O")//偏头
            {
                if (ceatc == "S")//侧切
                {
                    double l = ic / 2 / Math.Cos(epsr / 2) / Math.Sin(epsr / 2);
                    Vector2 v4 = new Vector2(dcon / 2, 0);
                    Vector2 v5 = new Vector2(v4.X, -lf + ldred);
                    Vector2 v6 = new Vector2(bdred / 2, v5.Y);
                    Vector2 v7 = new Vector2(v6.X, -lf + lh);
                    Vector2 v11 = new Vector2(wf, -lf);
                    Vector2 v10 = new Vector2(v11.X - l * Math.Sin(kapr - pi/2), v11.Y + l * Math.Cos(kapr - pi/2));
                    Vector2 v12 = new Vector2(v11.X-l*Math.Cos(pi-kapr-epsr), v11.Y + l * Math.Sin(pi - kapr - epsr));
                    Vector2 v14 = new Vector2(v10.X - l * Math.Cos(pi - kapr - epsr), v10.Y+ l * Math.Sin(pi - kapr - epsr));
                    Vector2 v9 = new Vector2(v10.X - kn0001 / Math.Sin(epsr)*Math.Cos(pi-kapr-epsr), v10.Y+ kn0001 / Math.Sin(epsr) * Math.Sin(pi - kapr - epsr));
                    Vector2 v13 = new Vector2(v12.X - kn0002 / Math.Cos(pi/2-epsr) * Math.Sin(pi-kapr - epsr), v12.Y + kn0002 / Math.Cos(pi / 2 - epsr) * Math.Cos(pi - kapr - epsr));
                    Vector2 v8 = new Vector2(v9.X, v7.Y - (v9.X-v7.X) * Math.Tan(hea));
                    Vector2 v15 = new Vector2(-v6.X + ecd, v13.Y);
                    Vector2 v16 = new Vector2(-v6.X, v15.Y + ecd / Math.Tan(eca));
                    Vector2 v17 = new Vector2(v16.X, v6.Y);
                    Vector2 v18 = new Vector2(-v5.X, v5.Y);
                    Vector2 v19 = new Vector2(-v4.X, v4.Y);
                    Vector2 v23 = new Vector2(0, 2);
                    Vector2 v24 = new Vector2(0, -lf - 2);
                    Vector2 v25 = new Vector2(v11.X+5, v11.Y);
                    //线段
                    //主视图
                    Vector2[] Line1 = { v4, v5 };
                    fun.drawBLine(dxf, Line1, 0.3, contour);
                    Vector2[] Line2 = { v6, v7 };
                    fun.drawBLine(dxf, Line2, 0.3, contour);
                    Vector2[] Line7 = { v7, v8 };
                    fun.drawBLine(dxf, Line7, 0.3, contour);
                    Vector2[] Line8 = { v8, v9 };
                    fun.drawBLine(dxf, Line8, 0.3, contour);
                    Vector2[] Line19 = { v14, v10 };
                    fun.drawBLine(dxf, Line19, 0.3, contour);
                    Vector2[] Line20 = { v10, v11 };
                    fun.drawBLine(dxf, Line20, 0.3, contour);
                    if (ecd != 0)
                    {
                        Vector2[] Line3 = { v17, v16 };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line4 = { v15, v16 };
                        fun.drawBLine(dxf, Line4, 0.3, contour);
                        Vector2[] Line5 = { v15, v13 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    if (ecd == 0)
                    {
                        Vector2[] Line3 = { v17, new Vector2(v16.X, v15.Y) };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line5 = { new Vector2(v16.X, v15.Y), v13 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    Vector2[] Line6 = { v12, v14 };
                    fun.drawBLine(dxf, Line6, 0.3, contour);
                    Vector2[] Line9 = { v11, v12 };
                    fun.drawBLine(dxf, Line9, 0.3, contour);
                    Vector2[] Line13 = { v5, v18 };
                    fun.drawBLine(dxf, Line13, 0.3, contour);
                    Vector2[] Line14 = { v18, v19 };
                    fun.drawBLine(dxf, Line14, 0.3, contour);
                    Vector2[] Line15 = { v19, v4 };
                    fun.drawBLine(dxf, Line15, 0.3, contour);
                    Line Line10 = new Line(v11, v10);
                    Line Line11 = new Line(v11, v12);
                    Line Line16 = new Line(v11, v25);
                    Line16.Layer = dimensioning;
                    dxf.AddEntity(Line16);
                    Vector2[] Line17 = { v23, v24 };
                    fun.drawPlinetype(dxf, Line17, 0.15, centre, Linetype.Center);
                    Vector2[] Line18 = { v7, new Vector2(v16.X, v7.Y) };
                    fun.drawBLine(dxf, Line18, 0.3, contour);
                    Line Line21 = new Line(v7, new Vector2(v8.X, v7.Y));
                    Line21.Layer = dimensioning;
                    dxf.AddEntity(Line21);
                    Line Line22 = new Line(v7, v8);
                    Line Line23 = new Line(v16, new Vector2(v16.X, v15.Y));
                    Line23.Layer = dimensioning;
                    dxf.AddEntity(Line23);
                    Line Line24 = new Line(v16, v15);
                    //标注样式
                    //箭头样式
                    DimensionStyle dimensionStyle = fun.CreateDimStyle();
                    dimensionStyle.ArrowSize = 3.5;
                        
                    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                    //文本样式
                    dimensionStyle.TextHeight = 3.5;
                    double offset = 10;
                    //线段尺寸标注
                    //尺寸1
                    if (lh != 0)
                    {
                        LinearDimension dim1 = new LinearDimension(new Line(v15, v7), -offset - (v7.X + v15.X) / 2 + v16.X, 270, dimensionStyle);
                        dim1.UserText = "LH = " + Math.Round(lh / scale, 2);
                        dxf.AddEntity(dim1);
                    }
                    //尺寸2
                    LinearDimension dim2 = new LinearDimension(new Line(v24, v11), -offset - (v11.Y - v24.Y) / 2, 0, dimensionStyle);
                    dim2.UserText = "WF = " + Math.Round(wf / scale, 2);
                    dxf.AddEntity(dim2);
                    //尺寸3
                    LinearDimension dim3 = new LinearDimension(new Line(v4, v11), offset * 2 + (v11.X - v4.X) / 2, 270, dimensionStyle);
                    dim3.UserText = "LPR.LF = " + Math.Round(lf / scale, 2);
                    dxf.AddEntity(dim3);
                    //尺寸4
                    LinearDimension dim4 = new LinearDimension(new Line(v6, v11), offset + (v11.X - v6.X) / 2, 270, dimensionStyle);
                    dim4.UserText = "LDRED = " + Math.Round(ldred / scale, 2);
                    dxf.AddEntity(dim4);
                    //尺寸5
                    if (ecd != 0)
                    {
                        LinearDimension dim5 = new LinearDimension(new Line(v15, v16), -offset - (v16.Y - v15.Y) / 2, 0, dimensionStyle);
                        dim5.UserText = "ECD = " + Math.Round(ecd / scale, 2);
                        dxf.AddEntity(dim5);
                    }
                    //尺寸6
                    LinearDimension dim6 = new LinearDimension(new Line(v19, v4), offset * 2, 0, dimensionStyle);
                    dim6.UserText = "DCON = Φ" + Math.Round(dcon / scale, 2);
                    dxf.AddEntity(dim6);
                    //尺寸7
                    Angular2LineDimension angdim7 = new Angular2LineDimension(Line22, Line21, offset, dimensionStyle);
                    angdim7.UserText = "HEA = " + Math.Round(hea / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim7);
                    //尺寸8
                    LinearDimension dim8 = new LinearDimension(new Line(v17, v6), offset - v5.Y, 0, dimensionStyle);
                    dim8.UserText = "BDRED = Φ" + Math.Round(bdred / scale, 2);
                    dxf.AddEntity(dim8);
                    //尺寸11
                    Angular2LineDimension angdim11 = new Angular2LineDimension(Line10, Line16, offset, dimensionStyle);
                    angdim11.UserText = "KAPR = " + Math.Round(kapr / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim11);
                    //尺寸10
                    if (ecd != 0)
                    {
                        Angular2LineDimension angdim10 = new Angular2LineDimension(Line23, Line24, offset, dimensionStyle);
                        angdim10.UserText = "ECA = " + Math.Round(eca / pi * 180, 2) + "°";
                        dxf.AddEntity(angdim10);
                    }
                    //尺寸14
                    LinearDimension dim14 = new LinearDimension(new Line(v14, v10), offset, (pi - kapr-epsr) / pi * 180, dimensionStyle);
                    dim14.UserText = "L = " + Math.Round(l / scale, 2);
                    dxf.AddEntity(dim14);
                }
                if (ceatc == "E")//端切
                {
                    double l = ic / 2 / Math.Cos(epsr / 2) / Math.Sin(epsr / 2);
                    double lpr = lf + l * Math.Cos(kapr);
                    Vector2 v4 = new Vector2(dcon/2, 0);
                    Vector2 v5 = new Vector2(v4.X, -lf+ldred);
                    Vector2 v6 = new Vector2(bdred/2, v5.Y);
                    Vector2 v7 = new Vector2(v6.X, -lpr + lh);
                    Vector2 v10 = new Vector2(wf, -lf);
                    Vector2 v9 = new Vector2(v10.X-l*Math.Sin(pi-kapr-epsr), v10.Y + l * Math.Cos(pi-kapr - epsr));
                    Vector2 v8 = new Vector2(v9.X, v7.Y - (v9.X - v7.X) / Math.Tan(hea));
                    Vector2 v11 = new Vector2(v10.X-l*Math.Sin(kapr), -lpr);
                    Vector2 v14 = new Vector2(v11.X-kn0002/Math.Sin(pi/2-kapr), v11.Y);
                    Vector2 v12 = new Vector2(v11.X-kn0002/Math.Sin(epsr)*Math.Cos(kapr+epsr-pi/2), v11.Y+ kn0002 / Math.Sin(epsr) * Math.Sin(kapr + epsr - pi / 2));
                    Vector2 v13 = new Vector2(v11.X- l * Math.Cos(kapr + epsr - pi / 2), v11.Y+ l * Math.Sin(kapr + epsr - pi / 2));
                    Vector2 v15 = new Vector2(-v6.X+ecd, v14.Y);
                    Vector2 v16 = new Vector2(-v6.X, v15.Y + ecd/Math.Tan(eca));
                    Vector2 v17 = new Vector2(v16.X, v6.Y);
                    Vector2 v18 = new Vector2(-v5.X, v5.Y);
                    Vector2 v19 = new Vector2(-v4.X, v4.Y);
                    Vector2 v23 = new Vector2(0, 2);
                    Vector2 v24 = new Vector2(0, -lpr-2);
                    Vector2 v25 = new Vector2(v10.X, v11.Y);
                    //线段
                    //主视图
                    Vector2[] Line1 = { v4, v5 };
                    fun.drawBLine(dxf, Line1, 0.3, contour);
                    Vector2[] Line2 = { v6, v7 };
                    fun.drawBLine(dxf, Line2, 0.3, contour);
                    Vector2[] Line7 = { v7, v8 };
                    fun.drawBLine(dxf, Line7, 0.3, contour);
                    Vector2[] Line8 = { v8, v9 };
                    fun.drawBLine(dxf, Line8, 0.3, contour);
                    Vector2[] Line19 = { v9, v10 };
                    fun.drawBLine(dxf, Line19, 0.3, contour);
                    Vector2[] Line20 = { v10, v11 };
                    fun.drawBLine(dxf, Line20, 0.3, contour);
                    if (ecd != 0)
                    {
                        Vector2[] Line3 = { v17, v16 };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line4 = { v15, v16 };
                        fun.drawBLine(dxf, Line4, 0.3, contour);
                        Vector2[] Line5 = { v15, v14 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    if (ecd == 0)
                    {
                        Vector2[] Line3 = { v17, new Vector2(v16.X,v15.Y) };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line5 = { new Vector2(v16.X,v15.Y), v14 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    Vector2[] Line6 = { v12, v14 };
                    fun.drawBLine(dxf, Line6, 0.3, contour);
                    Vector2[] Line9 = { v11, v13 };
                    fun.drawBLine(dxf, Line9, 0.3, contour);
                    Vector2[] Line12 = { v9, v13 };
                    fun.drawBLine(dxf, Line12, 0.3, contour);
                    Vector2[] Line13 = { v5, v18 };
                    fun.drawBLine(dxf, Line13, 0.3, contour);
                    Vector2[] Line14 = { v18, v19 };
                    fun.drawBLine(dxf, Line14, 0.3, contour);
                    Vector2[] Line15 = { v19, v4 };
                    fun.drawBLine(dxf, Line15, 0.3, contour);
                    Line Line10 = new Line(v10, v11);
                    Line Line11 = new Line(v10, v9);
                    Line Line16 = new Line(v10, v25);
                    Line16.Layer = dimensioning;
                    dxf.AddEntity(Line16);
                    Vector2[] Line17 = { v23, v24 };
                    fun.drawPlinetype(dxf, Line17, 0.15, centre, Linetype.Center);
                    Vector2[] Line18 = { v7, new Vector2(v16.X,v7.Y) };
                    fun.drawBLine(dxf, Line18, 0.3, contour);
                    Line Line21 = new Line(v7, new Vector2(v8.X,v7.Y));
                    Line21.Layer = dimensioning;
                    dxf.AddEntity(Line21);
                    Line Line22 = new Line(v7, v8);
                    Line Line23 = new Line(v16, new Vector2(v16.X, v15.Y));
                    Line23.Layer = dimensioning;
                    dxf.AddEntity(Line23);
                    Line Line24 = new Line(v16, v15);
                    //标注样式
                    //箭头样式
                    DimensionStyle dimensionStyle = fun.CreateDimStyle();
                    dimensionStyle.ArrowSize = 0.2;
                    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                    //文本样式
                    dimensionStyle.TextHeight = 1.0;
                    double offset = 10;
                    //线段尺寸标注
                    //尺寸1
                    if (lh != 0)
                    {
                        LinearDimension dim1 = new LinearDimension(new Line(v15, v7), -offset - (v7.X+v15.X) / 2+v16.X, 270, dimensionStyle);
                        dim1.UserText = "LH = " + Math.Round(lh / scale, 2);
                        dxf.AddEntity(dim1);
                    }
                    //尺寸2
                    LinearDimension dim2 = new LinearDimension(new Line(v24, v10), -offset - (v10.Y - v24.Y) / 2, 0, dimensionStyle);
                    dim2.UserText = "WF = " + Math.Round(wf / scale, 2);
                    dxf.AddEntity(dim2);
                    //尺寸3
                    LinearDimension dim3 = new LinearDimension(new Line(v4, v10), offset*2 + (v10.X - v4.X) / 2, 270, dimensionStyle);
                    dim3.UserText = "LF = " + Math.Round(lf / scale, 2);
                    dxf.AddEntity(dim3);
                    //尺寸4
                    LinearDimension dim4 = new LinearDimension(new Line(v6, v10), offset + (v10.X - v6.X) / 2, 270, dimensionStyle);
                    dim4.UserText = "LDRED = " + Math.Round(ldred / scale, 2);
                    dxf.AddEntity(dim4);
                    //尺寸5
                    if (ecd != 0)
                    {
                        LinearDimension dim5 = new LinearDimension(new Line(v15, v16), -offset - (v16.Y - v15.Y) / 2, 0, dimensionStyle);
                        dim5.UserText = "ECD = " + Math.Round(ecd / scale, 2);
                        dxf.AddEntity(dim5);
                    }
                    //尺寸6
                    LinearDimension dim6 = new LinearDimension(new Line(v19, v4), offset*2, 0, dimensionStyle);
                    dim6.UserText = "DCON = Φ" + Math.Round(dcon / scale, 2);
                    dxf.AddEntity(dim6);
                    //尺寸7
                    Angular2LineDimension angdim7 = new Angular2LineDimension(Line22, Line21, offset, dimensionStyle);
                    angdim7.UserText = "HEA = " + Math.Round(hea / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim7);
                    //尺寸8
                    LinearDimension dim8 = new LinearDimension(new Line(v17, v6), offset-v5.Y, 0, dimensionStyle);
                    dim8.UserText = "BDRED = Φ" + Math.Round(bdred / scale, 2);
                    dxf.AddEntity(dim8);
                    //尺寸11
                    Angular2LineDimension angdim11 = new Angular2LineDimension(Line10, Line16, offset, dimensionStyle);
                    angdim11.UserText = "KAPR = " + Math.Round(kapr / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim11);
                    //尺寸10
                    if (ecd != 0)
                    {
                        Angular2LineDimension angdim10 = new Angular2LineDimension(Line23, Line24, offset, dimensionStyle);
                        angdim10.UserText = "ECA = " + Math.Round(eca / pi * 180, 2) + "°";
                        dxf.AddEntity(angdim10);
                    }
                    //尺寸12
                    LinearDimension dim12 = new LinearDimension(new Line(v4, v11), offset*3+v10.X-(v4.X+v11.X)/2, 270, dimensionStyle);
                    dim12.UserText = "LPR = " + Math.Round(lpr / scale, 2);
                    dxf.AddEntity(dim12);
                    //尺寸14
                    LinearDimension dim14 = new LinearDimension(new Line(v13, v9), offset, (pi / 2-kapr) / pi * 180, dimensionStyle);
                    dim14.UserText = "L = " + Math.Round(l / scale, 2);
                    dxf.AddEntity(dim14);
                }
            }
            if (thsc == "S")//直头
            {
                if (ceatc == "S")//侧切
                {
                    double l = ic / 2 / Math.Cos(epsr / 2) / Math.Sin(epsr / 2);
                    Vector2 v4 = new Vector2(dcon / 2, 0);
                    Vector2 v5 = new Vector2(v4.X, -lf + ldred);
                    Vector2 v6 = new Vector2(bdred / 2, v5.Y);
                    Vector2 v11 = new Vector2(wf, -lf);
                    Vector2 v10 = new Vector2(v11.X - l * Math.Sin(kapr - pi / 2), v11.Y + l * Math.Cos(kapr - pi / 2));
                    Vector2 v12 = new Vector2(v11.X - l * Math.Cos(pi - kapr - epsr), v11.Y + l * Math.Sin(pi - kapr - epsr));
                    Vector2 v14 = new Vector2(v10.X - l * Math.Cos(pi - kapr - epsr), v10.Y + l * Math.Sin(pi - kapr - epsr));
                    Vector2 v9 = new Vector2(v6.X, v14.Y - (v6.X - v14.X) * Math.Sin(pi - kapr - epsr));
                    Vector2 v13 = new Vector2(v12.X - kn0002 / Math.Cos(pi / 2 - epsr) * Math.Sin(pi - kapr - epsr), v12.Y + kn0002 / Math.Cos(pi / 2 - epsr) * Math.Cos(pi - kapr - epsr));
                    Vector2 v15 = new Vector2(-v6.X + ecd, v13.Y);
                    Vector2 v16 = new Vector2(-v6.X, v15.Y + ecd / Math.Tan(eca));
                    Vector2 v17 = new Vector2(v16.X, v6.Y);
                    Vector2 v18 = new Vector2(-v5.X, v5.Y);
                    Vector2 v19 = new Vector2(-v4.X, v4.Y);
                    Vector2 v23 = new Vector2(0, 2);
                    Vector2 v24 = new Vector2(0, -lf - 2);
                    Vector2 v25 = new Vector2(v11.X + 5, v11.Y);
                    //线段
                    //主视图
                    Vector2[] Line1 = { v4, v5 };
                    fun.drawBLine(dxf, Line1, 0.3, contour);
                    Vector2[] Line2 = { v6, v9 };
                    fun.drawBLine(dxf, Line2, 0.3, contour);
                    Vector2[] Line19 = { v14, v10 };
                    fun.drawBLine(dxf, Line19, 0.3, contour);
                    Vector2[] Line20 = { v10, v11 };
                    fun.drawBLine(dxf, Line20, 0.3, contour);
                    if (ecd != 0)
                    {
                        Vector2[] Line3 = { v17, v16 };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line4 = { v15, v16 };
                        fun.drawBLine(dxf, Line4, 0.3, contour);
                        Vector2[] Line5 = { v15, v13 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    if (ecd == 0)
                    {
                        Vector2[] Line3 = { v17, new Vector2(v16.X, v15.Y) };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line5 = { new Vector2(v16.X, v15.Y), v13 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    Vector2[] Line6 = { v12, v14 };
                    fun.drawBLine(dxf, Line6, 0.3, contour);
                    Vector2[] Line9 = { v11, v12 };
                    fun.drawBLine(dxf, Line9, 0.3, contour);
                    Vector2[] Line13 = { v5, v18 };
                    fun.drawBLine(dxf, Line13, 0.3, contour);
                    Vector2[] Line14 = { v18, v19 };
                    fun.drawBLine(dxf, Line14, 0.3, contour);
                    Vector2[] Line15 = { v19, v4 };
                    fun.drawBLine(dxf, Line15, 0.3, contour);
                    Line Line10 = new Line(v11, v10);
                    Line Line11 = new Line(v11, v12);
                    Line Line16 = new Line(v11, v25);
                    Line16.Layer = dimensioning;
                    dxf.AddEntity(Line16);
                    Vector2[] Line17 = { v23, v24 };
                    fun.drawPlinetype(dxf, Line17, 0.15, centre, Linetype.Center);
                    Line Line23 = new Line(v16, new Vector2(v16.X, v15.Y));
                    Line23.Layer = dimensioning;
                    dxf.AddEntity(Line23);
                    Line Line24 = new Line(v16, v15);
                    //标注样式
                    //箭头样式
                    DimensionStyle dimensionStyle = fun.CreateDimStyle();
                    dimensionStyle.ArrowSize = 0.2;
                    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                    //文本样式
                    dimensionStyle.TextHeight = 1.0;
                    double offset = 10;
                    //线段尺寸标注
                    //尺寸1
                    //尺寸2
                    LinearDimension dim2 = new LinearDimension(new Line(v24, v11), -offset - (v11.Y - v24.Y) / 2, 0, dimensionStyle);
                    dim2.UserText = "WF = " + Math.Round(wf / scale, 2);
                    dxf.AddEntity(dim2);
                    //尺寸3
                    LinearDimension dim3 = new LinearDimension(new Line(v4, v11), offset * 2 + (v11.X - v4.X) / 2, 270, dimensionStyle);
                    dim3.UserText = "LPR.LF = " + Math.Round(lf / scale, 2);
                    dxf.AddEntity(dim3);
                    //尺寸4
                    LinearDimension dim4 = new LinearDimension(new Line(v6, v11), offset + (v11.X - v6.X) / 2, 270, dimensionStyle);
                    dim4.UserText = "LDRED = " + Math.Round(ldred / scale, 2);
                    dxf.AddEntity(dim4);
                    //尺寸5
                    if (ecd != 0)
                    {
                        LinearDimension dim5 = new LinearDimension(new Line(v15, v16), -offset - (v16.Y - v15.Y) / 2, 0, dimensionStyle);
                        dim5.UserText = "ECD = " + Math.Round(ecd / scale, 2);
                        dxf.AddEntity(dim5);
                    }
                    //尺寸6
                    LinearDimension dim6 = new LinearDimension(new Line(v19, v4), offset * 2, 0, dimensionStyle);
                    dim6.UserText = "DCON = Φ" + Math.Round(dcon / scale, 2);
                    dxf.AddEntity(dim6);
                    //尺寸8
                    LinearDimension dim8 = new LinearDimension(new Line(v17, v6), offset - v5.Y, 0, dimensionStyle);
                    dim8.UserText = "BDRED = Φ" + Math.Round(bdred / scale, 2);
                    dxf.AddEntity(dim8);
                    //尺寸11
                    Angular2LineDimension angdim11 = new Angular2LineDimension(Line10, Line16, offset, dimensionStyle);
                    angdim11.UserText = "KAPR = " + Math.Round(kapr / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim11);
                    //尺寸10
                    if (ecd != 0)
                    {
                        Angular2LineDimension angdim10 = new Angular2LineDimension(Line23, Line24, offset, dimensionStyle);
                        angdim10.UserText = "ECA = " + Math.Round(eca / pi * 180, 2) + "°";
                        dxf.AddEntity(angdim10);
                    }
                    //尺寸14
                    LinearDimension dim14 = new LinearDimension(new Line(v14, v10), offset, (pi - kapr - epsr) / pi * 180, dimensionStyle);
                    dim14.UserText = "L = " + Math.Round(l / scale, 2);
                    dxf.AddEntity(dim14);
                }
                if (ceatc == "E")//端切
                {
                    double l = ic / 2 / Math.Cos(epsr / 2) / Math.Sin(epsr / 2);
                    double lpr = lf + l * Math.Cos(kapr);
                    Vector2 v4 = new Vector2(dcon / 2, 0);
                    Vector2 v5 = new Vector2(v4.X, -lf + ldred);
                    Vector2 v6 = new Vector2(bdred / 2, v5.Y);
                    Vector2 v10 = new Vector2(wf, -lf);
                    Vector2 v8 = new Vector2(v10.X - l * Math.Sin(pi - kapr - epsr), v10.Y + l * Math.Cos(pi - kapr - epsr));
                    Vector2 v9 = new Vector2(v6.X, v10.Y + (v10.X-v6.X) * Math.Tan(kapr + epsr-pi/2));
                    Vector2 v11 = new Vector2(v10.X - l * Math.Sin(kapr), -lpr);
                    Vector2 v14 = new Vector2(v11.X - kn0002 / Math.Sin(pi / 2 - kapr), v11.Y);
                    Vector2 v12 = new Vector2(v11.X - kn0002 / Math.Sin(epsr) * Math.Cos(kapr + epsr - pi / 2), v11.Y + kn0002 / Math.Sin(epsr) * Math.Sin(kapr + epsr - pi / 2));
                    Vector2 v13 = new Vector2(v11.X - l * Math.Cos(kapr + epsr - pi / 2), v11.Y + l * Math.Sin(kapr + epsr - pi / 2));
                    Vector2 v15 = new Vector2(-v6.X + ecd, v14.Y);
                    Vector2 v16 = new Vector2(-v6.X, v15.Y + ecd / Math.Tan(eca));
                    Vector2 v17 = new Vector2(v16.X, v6.Y);
                    Vector2 v18 = new Vector2(-v5.X, v5.Y);
                    Vector2 v19 = new Vector2(-v4.X, v4.Y);
                    Vector2 v23 = new Vector2(0, 2);
                    Vector2 v24 = new Vector2(0, -lpr - 2);
                    Vector2 v25 = new Vector2(v10.X, v11.Y);
                    //线段
                    //主视图
                    Vector2[] Line1 = { v4, v5 };
                    fun.drawBLine(dxf, Line1, 0.3, contour);
                    Vector2[] Line2 = { v6, v9 };
                    fun.drawBLine(dxf, Line2, 0.3, contour);
                    Vector2[] Line19 = { v8, v10 };
                    fun.drawBLine(dxf, Line19, 0.3, contour);
                    Vector2[] Line20 = { v10, v11 };
                    fun.drawBLine(dxf, Line20, 0.3, contour);
                    if (ecd != 0)
                    {
                        Vector2[] Line3 = { v17, v16 };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line4 = { v15, v16 };
                        fun.drawBLine(dxf, Line4, 0.3, contour);
                        Vector2[] Line5 = { v15, v14 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    if (ecd == 0)
                    {
                        Vector2[] Line3 = { v17, new Vector2(v16.X, v15.Y) };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line5 = { new Vector2(v16.X, v15.Y), v14 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    Vector2[] Line6 = { v12, v14 };
                    fun.drawBLine(dxf, Line6, 0.3, contour);
                    Vector2[] Line9 = { v11, v13 };
                    fun.drawBLine(dxf, Line9, 0.3, contour);
                    Vector2[] Line12 = { v8, v13 };
                    fun.drawBLine(dxf, Line12, 0.3, contour);
                    Vector2[] Line13 = { v5, v18 };
                    fun.drawBLine(dxf, Line13, 0.3, contour);
                    Vector2[] Line14 = { v18, v19 };
                    fun.drawBLine(dxf, Line14, 0.3, contour);
                    Vector2[] Line15 = { v19, v4 };
                    fun.drawBLine(dxf, Line15, 0.3, contour);
                    Line Line10 = new Line(v10, v11);
                    Line Line11 = new Line(v10, v8);
                    Line Line16 = new Line(v10, v25);
                    Line16.Layer = dimensioning;
                    dxf.AddEntity(Line16);
                    Vector2[] Line17 = { v23, v24 };
                    fun.drawPlinetype(dxf, Line17, 0.15, centre, Linetype.Center);
                    Line Line23 = new Line(v16, new Vector2(v16.X, v15.Y));
                    Line23.Layer = dimensioning;
                    dxf.AddEntity(Line23);
                    Line Line24 = new Line(v16, v15);
                    //标注样式
                    //箭头样式
                    DimensionStyle dimensionStyle = fun.CreateDimStyle();
                    dimensionStyle.ArrowSize = 0.2;
                    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                    //文本样式
                    dimensionStyle.TextHeight = 1.0;
                    double offset = 10;
                    //线段尺寸标注
                    //尺寸2
                    LinearDimension dim2 = new LinearDimension(new Line(v24, v10), -offset - (v10.Y - v24.Y) / 2, 0, dimensionStyle);
                    dim2.UserText = "WF = " + Math.Round(wf / scale, 2);
                    dxf.AddEntity(dim2);
                    //尺寸3
                    LinearDimension dim3 = new LinearDimension(new Line(v4, v10), offset * 2 + (v10.X - v4.X) / 2, 270, dimensionStyle);
                    dim3.UserText = "LF = " + Math.Round(lf / scale, 2);
                    dxf.AddEntity(dim3);
                    //尺寸4
                    LinearDimension dim4 = new LinearDimension(new Line(v6, v10), offset + (v10.X - v6.X) / 2, 270, dimensionStyle);
                    dim4.UserText = "LDRED = " + Math.Round(ldred / scale, 2);
                    dxf.AddEntity(dim4);
                    //尺寸5
                    if (ecd != 0)
                    {
                        LinearDimension dim5 = new LinearDimension(new Line(v15, v16), -offset - (v16.Y - v15.Y) / 2, 0, dimensionStyle);
                        dim5.UserText = "ECD = " + Math.Round(ecd / scale, 2);
                        dxf.AddEntity(dim5);
                    }
                    //尺寸6
                    LinearDimension dim6 = new LinearDimension(new Line(v19, v4), offset * 2, 0, dimensionStyle);
                    dim6.UserText = "DCON = Φ" + Math.Round(dcon / scale, 2);
                    dxf.AddEntity(dim6);
                    //尺寸8
                    LinearDimension dim8 = new LinearDimension(new Line(v17, v6), offset - v5.Y, 0, dimensionStyle);
                    dim8.UserText = "BDRED = Φ" + Math.Round(bdred / scale, 2);
                    dxf.AddEntity(dim8);
                    //尺寸11
                    Angular2LineDimension angdim11 = new Angular2LineDimension(Line10, Line16, offset, dimensionStyle);
                    angdim11.UserText = "KAPR = " + Math.Round(kapr / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim11);
                    //尺寸10
                    if (ecd != 0)
                    {
                        Angular2LineDimension angdim10 = new Angular2LineDimension(Line23, Line24, offset, dimensionStyle);
                        angdim10.UserText = "ECA = " + Math.Round(eca / pi * 180, 2) + "°";
                        dxf.AddEntity(angdim10);
                    }
                    //尺寸12
                    LinearDimension dim12 = new LinearDimension(new Line(v4, v11), offset * 3 + v10.X - (v4.X + v11.X) / 2, 270, dimensionStyle);
                    dim12.UserText = "LPR = " + Math.Round(lpr / scale, 2);
                    dxf.AddEntity(dim12);
                    //尺寸14
                    LinearDimension dim14 = new LinearDimension(new Line(v13, v9), offset, (pi / 2 - kapr) / pi * 180, dimensionStyle);
                    dim14.UserText = "L = " + Math.Round(l / scale, 2);
                    dxf.AddEntity(dim14);
                }
            }
            //图框
            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA3Y(dxf, new Vector2(-148.5, 210-lf/2));
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void SystemToolForExternalThreading(Dictionary<string, Object> data) //12.外螺纹车削工具系统
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
            //作图
            //参数
            string path = Convert.ToString(data["path"]);
            double slf = Convert.ToDouble(data["lf"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0)
            {
                if (slf < 33.5)
                {
                    scale = 4.0;
                }
                else if (slf < 45)
                {
                    scale = 3.0;
                }
                else if (slf < 67)
                {
                    scale = 2.0;
                }
                else if (slf < 89)
                {
                    scale = 1.5;
                }
                else if (slf < 134)
                {
                    scale = 1.0;
                }
                else if (slf < 179)
                {
                    scale = 0.75;
                }
                else
                {
                    scale = 0.5;
                }
            }
            double pi = Math.PI;
            double lf = Convert.ToDouble(data["lf"]) * scale;
            double bdred = Convert.ToDouble(data["bdred"]) * scale;
            double lh = Convert.ToDouble(data["lh"]) * scale;
            double dcon = Convert.ToDouble(data["dcon"]) * scale;
            double ldred = Convert.ToDouble(data["ldred"]) * scale;
            double wf = Convert.ToDouble(data["wf"]) * scale;
            double ic = Convert.ToDouble(data["ic"]) * scale;
            double ecd = Convert.ToDouble(data["ecd"]) * scale;
            double eca = Convert.ToDouble(data["eca"]) * pi / 180;
            double hea = Convert.ToDouble(data["hea"]) * pi / 180;
            double cdx = Convert.ToDouble(data["cdx"]) * scale;
            double isframe = Convert.ToDouble(data["isframe"]);
            //坐标
            //主视图
            double l = ic * (1 + Math.Cos(pi / 3)) / 2 / Math.Cos(pi / 3) / Math.Sin(pi / 3);
            Vector2 v4 = new Vector2(dcon / 2, 0);
            Vector2 v5 = new Vector2(v4.X, -lf + ldred);
            Vector2 v6 = new Vector2(bdred / 2, v5.Y);
            Vector2 v7 = new Vector2(v6.X, -lf + lh);
            Vector2 v11 = new Vector2(wf, -lf);
            Vector2 v10 = new Vector2(v11.X - l * Math.Sin(pi / 3), v11.Y + l * Math.Cos(pi / 3));
            Vector2 v9 = new Vector2(v11.X, v11.Y + l);
            Vector2 v12 = new Vector2(v11.X - cdx * Math.Tan(pi/3), v11.Y + cdx);
            Vector2 v8 = new Vector2(v9.X, v7.Y - (v9.X - v7.X) * Math.Tan(hea));
            Vector2 v13 = new Vector2(-v6.X + ecd, v12.Y);
            Vector2 v14 = new Vector2(-v6.X, v13.Y + ecd / Math.Tan(eca));
            Vector2 v15 = new Vector2(v14.X, v7.Y);
            Vector2 v16 = new Vector2(v15.X, v6.Y);
            Vector2 v17 = new Vector2(-v5.X, v5.Y);
            Vector2 v18 = new Vector2(-v4.X, v4.Y);
            Vector2 v19 = new Vector2(0, 2);
            Vector2 v20 = new Vector2(0, -lf - 2);
            Vector2 v21 = new Vector2(v14.X, v13.Y);
            Vector2 v22 = new Vector2(v8.X, v7.Y);
            //线段
            //主视图
            Vector2[] Line1 = { v4, v5 };
            fun.drawBLine(dxf, Line1, 0.3, contour);
            Vector2[] Line2 = { v6, v7 };
            fun.drawBLine(dxf, Line2, 0.3, contour);
            Vector2[] Line7 = { v7, v8 };
            fun.drawBLine(dxf, Line7, 0.3, contour);
            Vector2[] Line8 = { v8, v11 };
            fun.drawBLine(dxf, Line8, 0.3, contour);
            Vector2[] Line19 = { v9, v10 };
            fun.drawBLine(dxf, Line19, 0.3, contour);
            Vector2[] Line20 = { v10, v11 };
            fun.drawBLine(dxf, Line20, 0.3, contour);
            if (ecd != 0)
            {
                Vector2[] Line3 = { v16, v14 };
                fun.drawBLine(dxf, Line3, 0.3, contour);
                Vector2[] Line4 = { v14, v13 };
                fun.drawBLine(dxf, Line4, 0.3, contour);
                Vector2[] Line5 = { v12, v13 };
                fun.drawBLine(dxf, Line5, 0.3, contour);
            }
            if (ecd == 0)
            {
                Vector2[] Line3 = { v16, v21 };
                fun.drawBLine(dxf, Line3, 0.3, contour);
                Vector2[] Line5 = { v21, v12 };
                fun.drawBLine(dxf, Line5, 0.3, contour);
            }
            Vector2[] Line6 = { v7, v15 };
            fun.drawBLine(dxf, Line6, 0.3, contour);
            Vector2[] Line9 = { v5, v17 };
            fun.drawBLine(dxf, Line9, 0.3, contour);
            Vector2[] Line13 = { v17, v18 };
            fun.drawBLine(dxf, Line13, 0.3, contour);
            Vector2[] Line14 = { v18, v4 };
            fun.drawBLine(dxf, Line14, 0.3, contour);
            Line Line10 = new Line(v11, v10);
            Line Line11 = new Line(v11, v9);
            Vector2[] Line17 = { v19, v20 };
            fun.drawPlinetype(dxf, Line17, 0.15, centre, Linetype.Center);
            Line Line21 = new Line(v7, v22);
            Line21.Layer = dimensioning;
            dxf.AddEntity(Line21);
            Line Line22 = new Line(v14, v13);
            Line Line23 = new Line(v14, v21);
            Line23.Layer = dimensioning;
            dxf.AddEntity(Line23);
            Line Line24 = new Line(v7, v8);
            //标注样式
            //箭头样式
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 3.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            //文本样式
            dimensionStyle.TextHeight = 3.5;
            double offset = 10;
            //线段尺寸标注
            //尺寸1
            if (lh != 0)
            {
                LinearDimension dim1 = new LinearDimension(new Line(v13, v7), -offset - (v7.X + v13.X) / 2 + v14.X, 270, dimensionStyle);
                dim1.UserText = "LH = " + Math.Round(lh / scale, 2);
                dxf.AddEntity(dim1);
            }
            //尺寸2
            LinearDimension dim2 = new LinearDimension(new Line(v20, v11), -offset - (v11.Y - v20.Y) / 2, 0, dimensionStyle);
            dim2.UserText = "WF = " + Math.Round(wf / scale, 2);
            dxf.AddEntity(dim2);
            //尺寸3
            LinearDimension dim3 = new LinearDimension(new Line(v4, v11), offset * 3 + (v11.X - v4.X) / 2, 270, dimensionStyle);
            dim3.UserText = "LPR.LF = " + Math.Round(lf / scale, 2);
            dxf.AddEntity(dim3);
            //尺寸4
            LinearDimension dim4 = new LinearDimension(new Line(v6, v11), offset*2 + (v11.X - v6.X) / 2, 270, dimensionStyle);
            dim4.UserText = "LDRED = " + Math.Round(ldred / scale, 2);
            dxf.AddEntity(dim4);
            //尺寸5
            if (ecd != 0)
            {
                LinearDimension dim5 = new LinearDimension(new Line(v13, v14), -offset - (v14.Y - v13.Y) / 2, 0, dimensionStyle);
                dim5.UserText = "ECD = " + Math.Round(ecd / scale, 2);
                dxf.AddEntity(dim5);
            }
            //尺寸6
            LinearDimension dim6 = new LinearDimension(new Line(v18, v4), offset * 2, 0, dimensionStyle);
            dim6.UserText = "DCON = Φ" + Math.Round(dcon / scale, 2);
            dxf.AddEntity(dim6);
            //尺寸7
            if ((v8.X - v7.X) != 0)
            {
                Angular2LineDimension angdim7 = new Angular2LineDimension(Line24, Line21, offset, dimensionStyle);
                angdim7.UserText = "HEA = " + Math.Round(hea / pi * 180, 2) + "°";
                dxf.AddEntity(angdim7);
            }
            //尺寸8
            LinearDimension dim8 = new LinearDimension(new Line(v16, v6), offset - v5.Y, 0, dimensionStyle);
            dim8.UserText = "BDRED = Φ" + Math.Round(bdred / scale, 2);
            dxf.AddEntity(dim8);
            //尺寸9
            LinearDimension dim9 = new LinearDimension(new Line(v12, v11), offset + (v11.X - v12.X) / 2, 270, dimensionStyle);
            dim9.UserText = "CDX = " + Math.Round(cdx / scale, 2);
            dxf.AddEntity(dim9);
            //尺寸10
            if (ecd != 0)
            {
                Angular2LineDimension angdim10 = new Angular2LineDimension(Line23, Line22, offset, dimensionStyle);
                angdim10.UserText = "ECA = " + Math.Round(eca / pi * 180, 2) + "°";
                dxf.AddEntity(angdim10);
            }
            //图框
            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA3Y(dxf, new Vector2(-148.5, 210 - lf / 2));
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void SystemToolForInternalTurning(Dictionary<string, Object> data) //13.内孔车削工具系统
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
            //作图
            //参数
            string path = Convert.ToString(data["path"]);
            double slf = Convert.ToDouble(data["lf"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0)
            {
                if (slf < 33.5)
                {
                    scale = 4.0;
                }
                else if (slf < 45)
                {
                    scale = 3.0;
                }
                else if (slf < 67)
                {
                    scale = 2.0;
                }
                else if (slf < 89)
                {
                    scale = 1.5;
                }
                else if (slf < 134)
                {
                    scale = 1.0;
                }
                else if (slf < 179)
                {
                    scale = 0.75;
                }
                else
                {
                    scale = 0.5;
                }
            }
            double pi = Math.PI;
            double lf = Convert.ToDouble(data["lf"]) * scale;
            double bdred = Convert.ToDouble(data["bdred"]) * scale;
            double lh = Convert.ToDouble(data["lh"]) * scale;
            double dcon = Convert.ToDouble(data["dcon"]) * scale;
            double ldred = Convert.ToDouble(data["ldred"]) * scale;
            double wf = Convert.ToDouble(data["wf"]) * scale;
            double ic = Convert.ToDouble(data["ic"]) * scale;
            double ecd = Convert.ToDouble(data["ecd"]) * scale;
            double kapr = Convert.ToDouble(data["kapr"]) * pi / 180;
            double eca = Convert.ToDouble(data["eca"]) * pi / 180;
            double hea = Convert.ToDouble(data["hea"]) * pi / 180;
            double epsr = Convert.ToDouble(data["epsr"]) * pi / 180;
            double kn0001 = Convert.ToDouble(data["kn0001"]) * scale;
            double kn0002 = Convert.ToDouble(data["kn0002"]) * scale;
            string thsc = Convert.ToString(data["thsc"]);
            string ceatc = Convert.ToString(data["ceatc"]);
            double isframe = Convert.ToDouble(data["isframe"]);
            //坐标
            //主视图
            if (thsc == "O")//偏头
            {
                if (ceatc == "S")//侧切
                {
                    double l = ic / 2 / Math.Cos(epsr / 2) / Math.Sin(epsr / 2);
                    Vector2 v4 = new Vector2(dcon / 2, 0);
                    Vector2 v5 = new Vector2(v4.X, -(lf - ldred) / 2);
                    Vector2 v6 = new Vector2(bdred / 2, -lf + ldred);
                    Vector2 v7 = new Vector2(v6.X, -lf + lh);
                    Vector2 v10 = new Vector2(wf, -lf);
                    Vector2 v9 = new Vector2(v10.X - l * Math.Sin(kapr - pi/2), v10.Y + l * Math.Cos(kapr - pi/2));
                    Vector2 v8 = new Vector2(v9.X, v7.Y - (v9.X - v7.X) / Math.Tan(hea));
                    Vector2 v11 = new Vector2(v10.X - l * Math.Cos(pi-kapr - epsr), v10.Y + l * Math.Sin(pi - kapr - epsr));
                    Vector2 v12 = new Vector2(v11.X - kn0002 / Math.Cos(pi / 2 - epsr) * Math.Cos(pi - kapr), v11.Y + kn0002 / Math.Cos(pi / 2 - epsr) * Math.Sin(pi - kapr));
                    Vector2 v13 = new Vector2(v11.X - l * Math.Cos(pi - kapr ), v11.Y + l * Math.Sin(pi - kapr));
                    Vector2 v14 = new Vector2(-v6.X + ecd, v12.Y);
                    Vector2 v15 = new Vector2(-v6.X, v14.Y + ecd / Math.Tan(eca));
                    Vector2 v16 = new Vector2(v15.X, v7.Y);
                    Vector2 v17 = new Vector2(-v6.X, v6.Y);
                    Vector2 v18 = new Vector2(-v5.X, v5.Y);
                    Vector2 v19 = new Vector2(-v4.X, v4.Y);
                    Vector2 v20 = new Vector2(0, 2);
                    Vector2 v21 = new Vector2(0, -lf - 2);
                    Vector2 v22 = new Vector2(v10.X+5, v10.Y);
                    Vector2 v23 = new Vector2(v15.X, v14.Y);
                    Vector2 v24 = new Vector2(v8.X, v7.Y);
                    //线段
                    //主视图
                    Vector2[] Line1 = { v4, v5 };
                    fun.drawBLine(dxf, Line1, 0.3, contour);
                    Vector2[] Line2 = { v6, v7 };
                    fun.drawBLine(dxf, Line2, 0.3, contour);
                    Vector2[] Line7 = { v7, v8 };
                    fun.drawBLine(dxf, Line7, 0.3, contour);
                    Vector2[] Line8 = { v8, v9 };
                    fun.drawBLine(dxf, Line8, 0.3, contour);
                    Vector2[] Line19 = { v9, v10 };
                    fun.drawBLine(dxf, Line19, 0.3, contour);
                    Vector2[] Line20 = { v10, v11 };
                    fun.drawBLine(dxf, Line20, 0.3, contour);
                    if (ecd != 0)
                    {
                        Vector2[] Line3 = { v15, v17 };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line4 = { v15, v14 };
                        fun.drawBLine(dxf, Line4, 0.3, contour);
                        Vector2[] Line5 = { v12, v14 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    if (ecd == 0)
                    {
                        Vector2[] Line3 = { v17, v23 };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line5 = { v23, v12 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    Vector2[] Line6 = { v9, v13 };
                    fun.drawBLine(dxf, Line6, 0.3, contour);
                    Vector2[] Line9 = { v7, v16 };
                    fun.drawBLine(dxf, Line9, 0.3, contour);
                    Vector2[] Line10 = { v11, v13 };
                    fun.drawBLine(dxf, Line10, 0.3, contour);
                    Vector2[] Line11 = { v5, v6 };
                    fun.drawBLine(dxf, Line11, 0.3, contour);
                    Vector2[] Line12 = { v6, v17 };
                    fun.drawBLine(dxf, Line12, 0.3, contour);
                    Vector2[] Line13 = { v5, v18 };
                    fun.drawBLine(dxf, Line13, 0.3, contour);
                    Vector2[] Line14 = { v18, v19 };
                    fun.drawBLine(dxf, Line14, 0.3, contour);
                    Vector2[] Line15 = { v19, v4 };
                    fun.drawBLine(dxf, Line15, 0.3, contour);
                    Line Line25 = new Line(v10, v11);
                    Line Line26 = new Line(v10, v22);
                    Line Line27 = new Line(v10, v9);
                    Line26.Layer = dimensioning;
                    dxf.AddEntity(Line26);
                    Vector2[] Line17 = { v20, v21 };
                    fun.drawPlinetype(dxf, Line17, 0.15, centre, Linetype.Center);
                    Vector2[] Line18 = { v17, v18 };
                    fun.drawBLine(dxf, Line18, 0.3, contour);
                    Line Line21 = new Line(v7, v24);
                    Line21.Layer = dimensioning;
                    dxf.AddEntity(Line21);
                    Line Line22 = new Line(v7, v8);
                    Line Line23 = new Line(v15, v23);
                    Line23.Layer = dimensioning;
                    dxf.AddEntity(Line23);
                    Line Line24 = new Line(v15, v14);
                    //标注样式
                    //箭头样式
                    DimensionStyle dimensionStyle = fun.CreateDimStyle();
                    dimensionStyle.ArrowSize = 0.2;
                    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                    //文本样式
                    dimensionStyle.TextHeight = 1.0;
                    double offset = 10;
                    //线段尺寸标注
                    //尺寸1
                    if (lh != 0)
                    {
                        LinearDimension dim1 = new LinearDimension(new Line(v10, v7), -offset - (v7.X + v10.X) / 2 + v16.X, 270, dimensionStyle);
                        dim1.UserText = "LH = " + Math.Round(lh / scale, 2);
                        dxf.AddEntity(dim1);
                    }
                    //尺寸2
                    LinearDimension dim2 = new LinearDimension(new Line(v21, v10), -offset * 2 - (v10.Y - v21.Y) / 2, 0, dimensionStyle);
                    dim2.UserText = "WF = " + Math.Round(wf / scale, 2);
                    dxf.AddEntity(dim2);
                    //尺寸3
                    LinearDimension dim3 = new LinearDimension(new Line(v4, v10), offset * 2 + (v10.X - v4.X) / 2, 270, dimensionStyle);
                    dim3.UserText = "LPR.LF = " + Math.Round(lf / scale, 2);
                    dxf.AddEntity(dim3);
                    //尺寸4
                    LinearDimension dim4 = new LinearDimension(new Line(v6, v10), offset + (v10.X - v6.X) / 2, 270, dimensionStyle);
                    dim4.UserText = "LDRED = " + Math.Round(ldred / scale, 2);
                    dxf.AddEntity(dim4);
                    //尺寸5
                    if (ecd != 0)
                    {
                        LinearDimension dim5 = new LinearDimension(new Line(v15, v14), -offset * 2 - (v15.Y - v14.Y) / 2 - v14.Y + v10.Y - 2, 0, dimensionStyle);
                        dim5.UserText = "ECD = " + Math.Round(ecd / scale, 2);
                        dxf.AddEntity(dim5);
                    }
                    //尺寸6
                    LinearDimension dim6 = new LinearDimension(new Line(v19, v4), offset * 2, 0, dimensionStyle);
                    dim6.UserText = "DCON = Φ" + Math.Round(dcon / scale, 2);
                    dxf.AddEntity(dim6);
                    //尺寸7
                    Angular2LineDimension angdim7 = new Angular2LineDimension(Line22, Line21, offset, dimensionStyle);
                    angdim7.UserText = "HEA = " + Math.Round(hea / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim7);
                    //尺寸8
                    LinearDimension dim8 = new LinearDimension(new Line(v17, v6), offset - v6.Y, 0, dimensionStyle);
                    dim8.UserText = "BDRED = Φ" + Math.Round(bdred / scale, 2);
                    dxf.AddEntity(dim8);
                    //尺寸9
                    Angular2LineDimension angdim9 = new Angular2LineDimension(Line25, Line27, offset * 1.5, dimensionStyle);
                    angdim9.UserText = "EPSR = " + Math.Round(epsr / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim9);
                    //尺寸11
                    Angular2LineDimension angdim11 = new Angular2LineDimension(Line27, Line26, offset, dimensionStyle);
                    angdim11.UserText = "KAPR = " + Math.Round(kapr / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim11);
                    //尺寸10
                    if (ecd != 0)
                    {
                        Angular2LineDimension angdim10 = new Angular2LineDimension(Line23, Line24, offset, dimensionStyle);
                        angdim10.UserText = "ECA = " + Math.Round(eca / pi * 180, 2) + "°";
                        dxf.AddEntity(angdim10);
                    }
                    //尺寸14
                    LinearDimension dim14 = new LinearDimension(new Line(v13, v9), offset, (pi / 2 - kapr) / pi * 180, dimensionStyle);
                    dim14.UserText = "L = " + Math.Round(l / scale, 2);
                    dxf.AddEntity(dim14);
                }
                if (ceatc == "E")//端切
                {
                    double l = ic / 2 / Math.Cos(epsr / 2) / Math.Sin(epsr / 2);
                    Vector2 v4 = new Vector2(dcon / 2, 0);
                    Vector2 v5 = new Vector2(v4.X, -(lf - ldred)/2);
                    Vector2 v6 = new Vector2(bdred / 2, -lf + ldred);
                    Vector2 v7 = new Vector2(v6.X, -lf + lh);
                    Vector2 v10 = new Vector2(wf, -lf);
                    Vector2 v9 = new Vector2(v10.X - l * Math.Sin(pi - kapr - epsr), v10.Y + l * Math.Cos(pi - kapr - epsr));
                    Vector2 v8 = new Vector2(v9.X, v7.Y - (v9.X - v7.X) / Math.Tan(hea));
                    Vector2 v11 = new Vector2(v10.X - l * Math.Cos(kapr-pi/2), v10.Y + l * Math.Sin(kapr - pi / 2));
                    Vector2 v12 = new Vector2(v11.X - kn0002 / Math.Cos(pi / 2 - epsr)*Math.Cos(epsr+kapr-pi/2), v11.Y+ kn0002 / Math.Cos(pi / 2 - epsr) * Math.Sin(epsr + kapr - pi / 2));
                    Vector2 v13 = new Vector2(v11.X - l * Math.Cos(kapr + epsr - pi / 2), v11.Y + l * Math.Sin(kapr + epsr - pi / 2));
                    Vector2 v14 = new Vector2(-v6.X + ecd, v12.Y);
                    Vector2 v15 = new Vector2(-v6.X, v14.Y + ecd / Math.Tan(eca));
                    Vector2 v16 = new Vector2(v15.X, v7.Y);
                    Vector2 v17 = new Vector2(-v6.X, v6.Y);
                    Vector2 v18 = new Vector2(-v5.X, v5.Y);
                    Vector2 v19 = new Vector2(-v4.X, v4.Y);
                    Vector2 v20 = new Vector2(0, 2);
                    Vector2 v21 = new Vector2(0, -lf - 2);
                    Vector2 v22 = new Vector2(v10.X, v10.Y-5);
                    Vector2 v23 = new Vector2(v15.X, v14.Y);
                    Vector2 v24 = new Vector2(v8.X, v7.Y);
                    //线段
                    //主视图
                    Vector2[] Line1 = { v4, v5 };
                    fun.drawBLine(dxf, Line1, 0.3, contour);
                    Vector2[] Line2 = { v6, v7 };
                    fun.drawBLine(dxf, Line2, 0.3, contour);
                    Vector2[] Line7 = { v7, v8 };
                    fun.drawBLine(dxf, Line7, 0.3, contour);
                    Vector2[] Line8 = { v8, v9 };
                    fun.drawBLine(dxf, Line8, 0.3, contour);
                    Vector2[] Line19 = { v9, v10 };
                    fun.drawBLine(dxf, Line19, 0.3, contour);
                    Vector2[] Line20 = { v10, v11 };
                    fun.drawBLine(dxf, Line20, 0.3, contour);
                    if (ecd != 0)
                    {
                        Vector2[] Line3 = { v15, v17 };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line4 = { v15, v14 };
                        fun.drawBLine(dxf, Line4, 0.3, contour);
                        Vector2[] Line5 = { v12, v14 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    if (ecd == 0)
                    {
                        Vector2[] Line3 = { v17, v23 };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line5 = { v23, v12 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    Vector2[] Line6 = { v9, v13 };
                    fun.drawBLine(dxf, Line6, 0.3, contour);
                    Vector2[] Line9 = { v7, v16 };
                    fun.drawBLine(dxf, Line9, 0.3, contour);
                    Vector2[] Line10 = { v11, v13 };
                    fun.drawBLine(dxf, Line10, 0.3, contour);
                    Vector2[] Line11 = { v5, v6 };
                    fun.drawBLine(dxf, Line11, 0.3, contour);
                    Vector2[] Line12 = { v6, v17 };
                    fun.drawBLine(dxf, Line12, 0.3, contour);
                    Vector2[] Line13 = { v5, v18 };
                    fun.drawBLine(dxf, Line13, 0.3, contour);
                    Vector2[] Line14 = { v18, v19 };
                    fun.drawBLine(dxf, Line14, 0.3, contour);
                    Vector2[] Line15 = { v19, v4 };
                    fun.drawBLine(dxf, Line15, 0.3, contour);
                    Line Line25 = new Line(v10, v11);
                    Line Line26 = new Line(v10, v22);
                    Line Line27 = new Line(v10, v9);
                    Line26.Layer = dimensioning;
                    dxf.AddEntity(Line26);
                    Vector2[] Line17 = { v20, v21 };
                    fun.drawPlinetype(dxf, Line17, 0.15, centre, Linetype.Center);
                    Vector2[] Line18 = { v17, v18 };
                    fun.drawBLine(dxf, Line18, 0.3, contour);
                    Line Line21 = new Line(v7, v24);
                    Line21.Layer = dimensioning;
                    dxf.AddEntity(Line21);
                    Line Line22 = new Line(v7, v8);
                    Line Line23 = new Line(v15, v23);
                    Line23.Layer = dimensioning;
                    dxf.AddEntity(Line23);
                    Line Line24 = new Line(v15, v14);
                    //标注样式
                    //箭头样式
                    DimensionStyle dimensionStyle = fun.CreateDimStyle();
                    dimensionStyle.ArrowSize = 0.2;
                    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                    //文本样式
                    dimensionStyle.TextHeight = 1.0;
                    double offset = 10;
                    //线段尺寸标注
                    //尺寸1
                    if (lh != 0)
                    {
                        LinearDimension dim1 = new LinearDimension(new Line(v10, v7), -offset - (v7.X + v10.X) / 2 + v16.X, 270, dimensionStyle);
                        dim1.UserText = "LH = " + Math.Round(lh / scale, 2);
                        dxf.AddEntity(dim1);
                    }
                    //尺寸2
                    LinearDimension dim2 = new LinearDimension(new Line(v21, v10), -offset*2 - (v10.Y - v21.Y) / 2, 0, dimensionStyle);
                    dim2.UserText = "WF = " + Math.Round(wf / scale, 2);
                    dxf.AddEntity(dim2);
                    //尺寸3
                    LinearDimension dim3 = new LinearDimension(new Line(v4, v10), offset * 2 + (v10.X - v4.X) / 2, 270, dimensionStyle);
                    dim3.UserText = "LPR.LF = " + Math.Round(lf / scale, 2);
                    dxf.AddEntity(dim3);
                    //尺寸4
                    LinearDimension dim4 = new LinearDimension(new Line(v6, v10), offset + (v10.X - v6.X) / 2, 270, dimensionStyle);
                    dim4.UserText = "LDRED = " + Math.Round(ldred / scale, 2);
                    dxf.AddEntity(dim4);
                    //尺寸5
                    if (ecd != 0)
                    {
                        LinearDimension dim5 = new LinearDimension(new Line(v15, v14), -offset*2 - (v15.Y - v14.Y) / 2-v14.Y+v10.Y-2, 0, dimensionStyle);
                        dim5.UserText = "ECD = " + Math.Round(ecd / scale, 2);
                        dxf.AddEntity(dim5);
                    }
                    //尺寸6
                    LinearDimension dim6 = new LinearDimension(new Line(v19, v4), offset * 2, 0, dimensionStyle);
                    dim6.UserText = "DCON = Φ" + Math.Round(dcon / scale, 2);
                    dxf.AddEntity(dim6);
                    //尺寸7
                    Angular2LineDimension angdim7 = new Angular2LineDimension(Line22, Line21, offset, dimensionStyle);
                    angdim7.UserText = "HEA = " + Math.Round(hea / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim7);
                    //尺寸8
                    LinearDimension dim8 = new LinearDimension(new Line(v17, v6), offset - v6.Y, 0, dimensionStyle);
                    dim8.UserText = "BDRED = Φ" + Math.Round(bdred / scale, 2);
                    dxf.AddEntity(dim8);
                    //尺寸9
                    Angular2LineDimension angdim9 = new Angular2LineDimension(Line25, Line27, offset*1.5, dimensionStyle);
                    angdim9.UserText = "EPSR = " + Math.Round(epsr / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim9);
                    //尺寸11
                    Angular2LineDimension angdim11 = new Angular2LineDimension(Line25, Line26, offset, dimensionStyle);
                    angdim11.UserText = "KAPR = " + Math.Round(kapr / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim11);
                    //尺寸10
                    if (ecd != 0)
                    {
                        Angular2LineDimension angdim10 = new Angular2LineDimension(Line23, Line24, offset, dimensionStyle);
                        angdim10.UserText = "ECA = " + Math.Round(eca / pi * 180, 2) + "°";
                        dxf.AddEntity(angdim10);
                    }
                    //尺寸14
                    LinearDimension dim14 = new LinearDimension(new Line(v13, v9), offset, (pi / 2 - kapr) / pi * 180, dimensionStyle);
                    dim14.UserText = "L = " + Math.Round(l / scale, 2);
                    dxf.AddEntity(dim14);
                }
            }
            if (thsc == "S")//直头
            {
                if (ceatc == "S")//侧切
                {
                    double l = ic / 2 / Math.Cos(epsr / 2) / Math.Sin(epsr / 2);
                    Vector2 v4 = new Vector2(dcon / 2, 0);
                    Vector2 v5 = new Vector2(v4.X, -(lf - ldred) / 2);
                    Vector2 v6 = new Vector2(bdred / 2, -lf + ldred);
                    Vector2 v10 = new Vector2(wf, -lf);
                    Vector2 v8 = new Vector2(v6.X, v10.Y + (v10.X - v6.X) * Math.Tan(kapr + epsr - pi / 2));
                    Vector2 v9 = new Vector2(v10.X - l * Math.Sin(kapr - pi / 2), v10.Y + l * Math.Cos(kapr - pi / 2));
                    Vector2 v11 = new Vector2(v10.X - l * Math.Cos(pi - kapr - epsr), v10.Y + l * Math.Sin(pi - kapr - epsr));
                    Vector2 v12 = new Vector2(v11.X - kn0002 / Math.Cos(pi / 2 - epsr) * Math.Cos(pi - kapr), v11.Y + kn0002 / Math.Cos(pi / 2 - epsr) * Math.Sin(pi - kapr));
                    Vector2 v13 = new Vector2(v11.X - l * Math.Cos(pi - kapr), v11.Y + l * Math.Sin(pi - kapr));
                    Vector2 v14 = new Vector2(-v6.X + ecd, v12.Y);
                    Vector2 v15 = new Vector2(-v6.X, v14.Y + ecd / Math.Tan(eca));
                    Vector2 v17 = new Vector2(-v6.X, v6.Y);
                    Vector2 v18 = new Vector2(-v5.X, v5.Y);
                    Vector2 v19 = new Vector2(-v4.X, v4.Y);
                    Vector2 v20 = new Vector2(0, 2);
                    Vector2 v21 = new Vector2(0, -lf - 2);
                    Vector2 v22 = new Vector2(v10.X+5, v10.Y);
                    Vector2 v23 = new Vector2(v15.X, v14.Y);
                    //线段
                    //主视图
                    Vector2[] Line1 = { v4, v5 };
                    fun.drawBLine(dxf, Line1, 0.3, contour);
                    Vector2[] Line2 = { v6, v8 };
                    fun.drawBLine(dxf, Line2, 0.3, contour);
                    Vector2[] Line19 = { v9, v10 };
                    fun.drawBLine(dxf, Line19, 0.3, contour);
                    Vector2[] Line20 = { v10, v11 };
                    fun.drawBLine(dxf, Line20, 0.3, contour);
                    if (ecd != 0)
                    {
                        Vector2[] Line3 = { v15, v17 };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line4 = { v15, v14 };
                        fun.drawBLine(dxf, Line4, 0.3, contour);
                        Vector2[] Line5 = { v12, v14 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    if (ecd == 0)
                    {
                        Vector2[] Line3 = { v17, v23 };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line5 = { v23, v12 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    Vector2[] Line6 = { v9, v13 };
                    fun.drawBLine(dxf, Line6, 0.3, contour);
                    Vector2[] Line10 = { v11, v13 };
                    fun.drawBLine(dxf, Line10, 0.3, contour);
                    Vector2[] Line11 = { v5, v6 };
                    fun.drawBLine(dxf, Line11, 0.3, contour);
                    Vector2[] Line12 = { v6, v17 };
                    fun.drawBLine(dxf, Line12, 0.3, contour);
                    Vector2[] Line13 = { v5, v18 };
                    fun.drawBLine(dxf, Line13, 0.3, contour);
                    Vector2[] Line14 = { v18, v19 };
                    fun.drawBLine(dxf, Line14, 0.3, contour);
                    Vector2[] Line15 = { v19, v4 };
                    fun.drawBLine(dxf, Line15, 0.3, contour);
                    Line Line25 = new Line(v10, v11);
                    Line Line26 = new Line(v10, v22);
                    Line Line27 = new Line(v10, v9);
                    Line26.Layer = dimensioning;
                    dxf.AddEntity(Line26);
                    Vector2[] Line17 = { v20, v21 };
                    fun.drawPlinetype(dxf, Line17, 0.15, centre, Linetype.Center);
                    Vector2[] Line18 = { v17, v18 };
                    fun.drawBLine(dxf, Line18, 0.3, contour);
                    Line Line23 = new Line(v15, v23);
                    Line23.Layer = dimensioning;
                    dxf.AddEntity(Line23);
                    Line Line24 = new Line(v15, v14);
                    //标注样式
                    //箭头样式
                    DimensionStyle dimensionStyle = fun.CreateDimStyle();
                    dimensionStyle.ArrowSize = 0.2;
                    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                    //文本样式
                    dimensionStyle.TextHeight = 1.0;
                    double offset = 10;
                    //线段尺寸标注
                    //尺寸1
                    //尺寸2
                    LinearDimension dim2 = new LinearDimension(new Line(v21, v10), -offset * 2 - (v10.Y - v21.Y) / 2, 0, dimensionStyle);
                    dim2.UserText = "WF = " + Math.Round(wf / scale, 2);
                    dxf.AddEntity(dim2);
                    //尺寸3
                    LinearDimension dim3 = new LinearDimension(new Line(v4, v10), offset * 2 + (v10.X - v4.X) / 2, 270, dimensionStyle);
                    dim3.UserText = "LPR.LF = " + Math.Round(lf / scale, 2);
                    dxf.AddEntity(dim3);
                    //尺寸4
                    LinearDimension dim4 = new LinearDimension(new Line(v6, v10), offset + (v10.X - v6.X) / 2, 270, dimensionStyle);
                    dim4.UserText = "LDRED = " + Math.Round(ldred / scale, 2);
                    dxf.AddEntity(dim4);
                    //尺寸5
                    if (ecd != 0)
                    {
                        LinearDimension dim5 = new LinearDimension(new Line(v15, v14), -offset * 2 - (v15.Y - v14.Y) / 2 - v14.Y + v10.Y - 2, 0, dimensionStyle);
                        dim5.UserText = "ECD = " + Math.Round(ecd / scale, 2);
                        dxf.AddEntity(dim5);
                    }
                    //尺寸6
                    LinearDimension dim6 = new LinearDimension(new Line(v19, v4), offset * 2, 0, dimensionStyle);
                    dim6.UserText = "DCON = Φ" + Math.Round(dcon / scale, 2);
                    dxf.AddEntity(dim6);
                    //尺寸8
                    LinearDimension dim8 = new LinearDimension(new Line(v17, v6), offset - v6.Y, 0, dimensionStyle);
                    dim8.UserText = "BDRED = Φ" + Math.Round(bdred / scale, 2);
                    dxf.AddEntity(dim8);
                    //尺寸9
                    Angular2LineDimension angdim9 = new Angular2LineDimension(Line25, Line27, offset * 1.5, dimensionStyle);
                    angdim9.UserText = "EPSR = " + Math.Round(epsr / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim9);
                    //尺寸11
                    Angular2LineDimension angdim11 = new Angular2LineDimension(Line27, Line26, offset, dimensionStyle);
                    angdim11.UserText = "KAPR = " + Math.Round(kapr / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim11);
                    //尺寸10
                    if (ecd != 0)
                    {
                        Angular2LineDimension angdim10 = new Angular2LineDimension(Line23, Line24, offset, dimensionStyle);
                        angdim10.UserText = "ECA = " + Math.Round(eca / pi * 180, 2) + "°";
                        dxf.AddEntity(angdim10);
                    }
                    //尺寸14
                    LinearDimension dim14 = new LinearDimension(new Line(v13, v9), offset, (pi / 2 - kapr) / pi * 180, dimensionStyle);
                    dim14.UserText = "L = " + Math.Round(l / scale, 2);
                    dxf.AddEntity(dim14);
                }
                if (ceatc == "E")//端切
                {
                    double l = ic / 2 / Math.Cos(epsr / 2) / Math.Sin(epsr / 2);
                    Vector2 v4 = new Vector2(dcon / 2, 0);
                    Vector2 v5 = new Vector2(v4.X, -(lf - ldred) / 2);
                    Vector2 v6 = new Vector2(bdred / 2, -lf + ldred);
                    Vector2 v10 = new Vector2(wf, -lf);
                    Vector2 v8 = new Vector2(v6.X, v10.Y + (v10.X - v6.X) * Math.Tan(kapr + epsr - pi / 2));
                    Vector2 v9 = new Vector2(v10.X - l * Math.Sin(pi - kapr - epsr), v10.Y + l * Math.Cos(pi - kapr - epsr));
                    Vector2 v11 = new Vector2(v10.X - l * Math.Cos(kapr - pi / 2), v10.Y + l * Math.Sin(kapr - pi / 2));
                    Vector2 v12 = new Vector2(v11.X - kn0002 / Math.Cos(pi / 2 - epsr) * Math.Cos(epsr + kapr - pi / 2), v11.Y + kn0002 / Math.Cos(pi / 2 - epsr) * Math.Sin(epsr + kapr - pi / 2));
                    Vector2 v13 = new Vector2(v11.X - l * Math.Cos(kapr + epsr - pi / 2), v11.Y + l * Math.Sin(kapr + epsr - pi / 2));
                    Vector2 v14 = new Vector2(-v6.X + ecd, v12.Y);
                    Vector2 v15 = new Vector2(-v6.X, v14.Y + ecd / Math.Tan(eca));
                    Vector2 v17 = new Vector2(-v6.X, v6.Y);
                    Vector2 v18 = new Vector2(-v5.X, v5.Y);
                    Vector2 v19 = new Vector2(-v4.X, v4.Y);
                    Vector2 v20 = new Vector2(0, 2);
                    Vector2 v21 = new Vector2(0, -lf - 2);
                    Vector2 v22 = new Vector2(v10.X, v10.Y - 5);
                    Vector2 v23 = new Vector2(v15.X, v14.Y);
                    //线段
                    //主视图
                    Vector2[] Line1 = { v4, v5 };
                    fun.drawBLine(dxf, Line1, 0.3, contour);
                    Vector2[] Line2 = { v6, v8 };
                    fun.drawBLine(dxf, Line2, 0.3, contour);
                    Vector2[] Line19 = { v9, v10 };
                    fun.drawBLine(dxf, Line19, 0.3, contour);
                    Vector2[] Line20 = { v10, v11 };
                    fun.drawBLine(dxf, Line20, 0.3, contour);
                    if (ecd != 0)
                    {
                        Vector2[] Line3 = { v15, v17 };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line4 = { v15, v14 };
                        fun.drawBLine(dxf, Line4, 0.3, contour);
                        Vector2[] Line5 = { v12, v14 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    if (ecd == 0)
                    {
                        Vector2[] Line3 = { v17, v23 };
                        fun.drawBLine(dxf, Line3, 0.3, contour);
                        Vector2[] Line5 = { v23, v12 };
                        fun.drawBLine(dxf, Line5, 0.3, contour);
                    }
                    Vector2[] Line6 = { v9, v13 };
                    fun.drawBLine(dxf, Line6, 0.3, contour);
                    Vector2[] Line10 = { v11, v13 };
                    fun.drawBLine(dxf, Line10, 0.3, contour);
                    Vector2[] Line11 = { v5, v6 };
                    fun.drawBLine(dxf, Line11, 0.3, contour);
                    Vector2[] Line12 = { v6, v17 };
                    fun.drawBLine(dxf, Line12, 0.3, contour);
                    Vector2[] Line13 = { v5, v18 };
                    fun.drawBLine(dxf, Line13, 0.3, contour);
                    Vector2[] Line14 = { v18, v19 };
                    fun.drawBLine(dxf, Line14, 0.3, contour);
                    Vector2[] Line15 = { v19, v4 };
                    fun.drawBLine(dxf, Line15, 0.3, contour);
                    Line Line25 = new Line(v10, v11);
                    Line Line26 = new Line(v10, v22);
                    Line Line27 = new Line(v10, v9);
                    Line26.Layer = dimensioning;
                    dxf.AddEntity(Line26);
                    Vector2[] Line17 = { v20, v21 };
                    fun.drawPlinetype(dxf, Line17, 0.15, centre, Linetype.Center);
                    Vector2[] Line18 = { v17, v18 };
                    fun.drawBLine(dxf, Line18, 0.3, contour);
                    Line Line23 = new Line(v15, v23);
                    Line23.Layer = dimensioning;
                    dxf.AddEntity(Line23);
                    Line Line24 = new Line(v15, v14);
                    //标注样式
                    //箭头样式
                    DimensionStyle dimensionStyle = fun.CreateDimStyle();
                    dimensionStyle.ArrowSize = 0.2;
                    dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
                    dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
                    //文本样式
                    dimensionStyle.TextHeight = 1.0;
                    double offset = 10;
                    //线段尺寸标注
                    //尺寸1
                    //尺寸2
                    LinearDimension dim2 = new LinearDimension(new Line(v21, v10), -offset * 2 - (v10.Y - v21.Y) / 2, 0, dimensionStyle);
                    dim2.UserText = "WF = " + Math.Round(wf / scale, 2);
                    dxf.AddEntity(dim2);
                    //尺寸3
                    LinearDimension dim3 = new LinearDimension(new Line(v4, v10), offset * 2 + (v10.X - v4.X) / 2, 270, dimensionStyle);
                    dim3.UserText = "LPR.LF = " + Math.Round(lf / scale, 2);
                    dxf.AddEntity(dim3);
                    //尺寸4
                    LinearDimension dim4 = new LinearDimension(new Line(v6, v10), offset + (v10.X - v6.X) / 2, 270, dimensionStyle);
                    dim4.UserText = "LDRED = " + Math.Round(ldred / scale, 2);
                    dxf.AddEntity(dim4);
                    //尺寸5
                    if (ecd != 0)
                    {
                        LinearDimension dim5 = new LinearDimension(new Line(v15, v14), -offset * 2 - (v15.Y - v14.Y) / 2 - v14.Y + v10.Y - 2, 0, dimensionStyle);
                        dim5.UserText = "ECD = " + Math.Round(ecd / scale, 2);
                        dxf.AddEntity(dim5);
                    }
                    //尺寸6
                    LinearDimension dim6 = new LinearDimension(new Line(v19, v4), offset * 2, 0, dimensionStyle);
                    dim6.UserText = "DCON = Φ" + Math.Round(dcon / scale, 2);
                    dxf.AddEntity(dim6);
                    //尺寸8
                    LinearDimension dim8 = new LinearDimension(new Line(v17, v6), offset - v6.Y, 0, dimensionStyle);
                    dim8.UserText = "BDRED = Φ" + Math.Round(bdred / scale, 2);
                    dxf.AddEntity(dim8);
                    //尺寸9
                    Angular2LineDimension angdim9 = new Angular2LineDimension(Line25, Line27, offset * 1.5, dimensionStyle);
                    angdim9.UserText = "EPSR = " + Math.Round(epsr / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim9);
                    //尺寸11
                    Angular2LineDimension angdim11 = new Angular2LineDimension(Line25, Line26, offset, dimensionStyle);
                    angdim11.UserText = "KAPR = " + Math.Round(kapr / pi * 180, 2) + "°";
                    dxf.AddEntity(angdim11);
                    //尺寸10
                    if (ecd != 0)
                    {
                        Angular2LineDimension angdim10 = new Angular2LineDimension(Line23, Line24, offset, dimensionStyle);
                        angdim10.UserText = "ECA = " + Math.Round(eca / pi * 180, 2) + "°";
                        dxf.AddEntity(angdim10);
                    }
                    //尺寸14
                    LinearDimension dim14 = new LinearDimension(new Line(v13, v9), offset, (pi / 2 - kapr) / pi * 180, dimensionStyle);
                    dim14.UserText = "L = " + Math.Round(l / scale, 2);
                    dxf.AddEntity(dim14);
                }
            }
            //图框
            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA3Y(dxf, new Vector2(-148.5, 210 - lf / 2));
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void SystemToolForInternalThreading(Dictionary<string, Object> data) //14.内螺纹车削工具系统
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
            //作图
            //参数
            string path = Convert.ToString(data["path"]);
            double slf = Convert.ToDouble(data["lf"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0)
            {
                if (slf < 33.5)
                {
                    scale = 4.0;
                }
                else if (slf < 45)
                {
                    scale = 3.0;
                }
                else if (slf < 67)
                {
                    scale = 2.0;
                }
                else if (slf < 89)
                {
                    scale = 1.5;
                }
                else if (slf < 134)
                {
                    scale = 1.0;
                }
                else if (slf < 179)
                {
                    scale = 0.75;
                }
                else
                {
                    scale = 0.5;
                }
            }
            double pi = Math.PI;
            double lf = Convert.ToDouble(data["lf"]) * scale;
            double bdred = Convert.ToDouble(data["bdred"]) * scale;
            double lh = Convert.ToDouble(data["lh"]) * scale;
            double dcon = Convert.ToDouble(data["dcon"]) * scale;
            double ldred = Convert.ToDouble(data["ldred"]) * scale;
            double wf = Convert.ToDouble(data["wf"]) * scale;
            double ic = Convert.ToDouble(data["ic"]) * scale;
            double ecd = Convert.ToDouble(data["ecd"]) * scale;
            double eca = Convert.ToDouble(data["eca"]) * pi / 180;
            double hea = Convert.ToDouble(data["hea"]) * pi / 180;
            double cdx = Convert.ToDouble(data["cdx"]) * scale;
            double isframe = Convert.ToDouble(data["isframe"]);
            //坐标
            //主视图
            double l = ic * (1 + Math.Cos(pi / 3)) / 2 / Math.Cos(pi / 3) / Math.Sin(pi / 3);
            Vector2 v4 = new Vector2(dcon / 2, 0);
            Vector2 v5 = new Vector2(v4.X, -lf + ldred);
            Vector2 v6 = new Vector2(bdred / 2, v5.Y);
            Vector2 v7 = new Vector2(v6.X, -lf + lh);
            Vector2 v11 = new Vector2(wf, -lf);
            Vector2 v10 = new Vector2(v11.X - l * Math.Cos(pi / 3), v11.Y + l * Math.Sin(pi / 3));
            Vector2 v9 = new Vector2(v11.X-l, v11.Y);
            Vector2 v12 = new Vector2(v11.X - cdx, v11.Y + cdx * Math.Tan(pi / 3));
            Vector2 v8 = new Vector2(v12.X, v7.Y - (v12.X - v7.X) * Math.Tan(hea));
            Vector2 v13 = new Vector2(-v6.X + ecd, v9.Y);
            Vector2 v14 = new Vector2(-v6.X, v13.Y + ecd / Math.Tan(eca));
            Vector2 v15 = new Vector2(v14.X, v7.Y);
            Vector2 v16 = new Vector2(v15.X, v6.Y);
            Vector2 v17 = new Vector2(-v5.X, v5.Y);
            Vector2 v18 = new Vector2(-v4.X, v4.Y);
            Vector2 v19 = new Vector2(0, 2);
            Vector2 v20 = new Vector2(0, -lf - 2);
            Vector2 v21 = new Vector2(v14.X, v13.Y);
            Vector2 v22 = new Vector2(v8.X, v7.Y);
            //线段
            //主视图
            Vector2[] Line1 = { v4, v5 };
            fun.drawBLine(dxf, Line1, 0.3, contour);
            Vector2[] Line2 = { v6, v7 };
            fun.drawBLine(dxf, Line2, 0.3, contour);
            Vector2[] Line7 = { v7, v8 };
            fun.drawBLine(dxf, Line7, 0.3, contour);
            Vector2[] Line8 = { v8, v12 };
            fun.drawBLine(dxf, Line8, 0.3, contour);
            Vector2[] Line19 = { v9, v10 };
            fun.drawBLine(dxf, Line19, 0.3, contour);
            Vector2[] Line20 = { v10, v11 };
            fun.drawBLine(dxf, Line20, 0.3, contour);
            if (ecd != 0)
            {
                Vector2[] Line3 = { v16, v14 };
                fun.drawBLine(dxf, Line3, 0.3, contour);
                Vector2[] Line4 = { v14, v13 };
                fun.drawBLine(dxf, Line4, 0.3, contour);
                Vector2[] Line5 = { v11, v13 };
                fun.drawBLine(dxf, Line5, 0.3, contour);
            }
            if (ecd == 0)
            {
                Vector2[] Line3 = { v16, v21 };
                fun.drawBLine(dxf, Line3, 0.3, contour);
                Vector2[] Line5 = { v21, v11 };
                fun.drawBLine(dxf, Line5, 0.3, contour);
            }
            Vector2[] Line6 = { v7, v15 };
            fun.drawBLine(dxf, Line6, 0.3, contour);
            Vector2[] Line9 = { v5, v17 };
            fun.drawBLine(dxf, Line9, 0.3, contour);
            Vector2[] Line13 = { v17, v18 };
            fun.drawBLine(dxf, Line13, 0.3, contour);
            Vector2[] Line14 = { v18, v4 };
            fun.drawBLine(dxf, Line14, 0.3, contour);
            Line Line10 = new Line(v11, v10);
            Line Line11 = new Line(v11, v9);
            Vector2[] Line17 = { v19, v20 };
            fun.drawPlinetype(dxf, Line17, 0.15, centre, Linetype.Center);
            Line Line21 = new Line(v7, v22);
            Line21.Layer = dimensioning;
            dxf.AddEntity(Line21);
            Line Line22 = new Line(v14, v13);
            Line Line23 = new Line(v14, v21);
            Line23.Layer = dimensioning;
            dxf.AddEntity(Line23);
            Line Line24 = new Line(v7, v8);
            //标注样式
            //箭头样式
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 3.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            //文本样式
            dimensionStyle.TextHeight = 3.5;
            double offset = 10;
            //线段尺寸标注
            //尺寸1
            if (lh != 0)
            {
                LinearDimension dim1 = new LinearDimension(new Line(v13, v7), -offset - (v7.X + v13.X) / 2 + v14.X, 270, dimensionStyle);
                dim1.UserText = "LH = " + Math.Round(lh / scale, 2);
                dxf.AddEntity(dim1);
            }
            //尺寸2
            LinearDimension dim2 = new LinearDimension(new Line(v20, v11), -offset*2 - (v11.Y - v20.Y) / 2, 0, dimensionStyle);
            dim2.UserText = "WF = " + Math.Round(wf / scale, 2);
            dxf.AddEntity(dim2);
            //尺寸3
            LinearDimension dim3 = new LinearDimension(new Line(v4, v11), offset * 2 + (v11.X - v4.X) / 2, 270, dimensionStyle);
            dim3.UserText = "LPR.LF = " + Math.Round(lf / scale, 2);
            dxf.AddEntity(dim3);
            //尺寸4
            LinearDimension dim4 = new LinearDimension(new Line(v6, v11), offset + (v11.X - v6.X) / 2, 270, dimensionStyle);
            dim4.UserText = "LDRED = " + Math.Round(ldred / scale, 2);
            dxf.AddEntity(dim4);
            //尺寸5
            if (ecd != 0)
            {
                LinearDimension dim5 = new LinearDimension(new Line(v13, v14), -offset*2-2 - (v14.Y - v13.Y) / 2, 0, dimensionStyle);
                dim5.UserText = "ECD = " + Math.Round(ecd / scale, 2);
                dxf.AddEntity(dim5);
            }
            //尺寸6
            LinearDimension dim6 = new LinearDimension(new Line(v18, v4), offset * 2, 0, dimensionStyle);
            dim6.UserText = "DCON = Φ" + Math.Round(dcon / scale, 2);
            dxf.AddEntity(dim6);
            //尺寸7
            if ((v8.X - v7.X) != 0)
            {
                Angular2LineDimension angdim7 = new Angular2LineDimension(Line24, Line21, offset, dimensionStyle);
                angdim7.UserText = "HEA = " + Math.Round(hea / pi * 180, 2) + "°";
                dxf.AddEntity(angdim7);
            }
            //尺寸8
            LinearDimension dim8 = new LinearDimension(new Line(v16, v6), offset - v5.Y, 0, dimensionStyle);
            dim8.UserText = "BDRED = Φ" + Math.Round(bdred / scale, 2);
            dxf.AddEntity(dim8);
            //尺寸9
            LinearDimension dim9 = new LinearDimension(new Line(v12, v11), -offset - (v12.Y - v11.Y) / 2, 0, dimensionStyle);
            dim9.UserText = "CDX = " + Math.Round(cdx / scale, 2);
            dxf.AddEntity(dim9);
            //尺寸10
            if (ecd != 0)
            {
                Angular2LineDimension angdim10 = new Angular2LineDimension(Line23, Line22, offset, dimensionStyle);
                angdim10.UserText = "ECA = " + Math.Round(eca / pi * 180, 2) + "°";
                dxf.AddEntity(angdim10);
            }
            //图框
            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA3Y(dxf, new Vector2(-148.5, 210 - lf / 2));
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void SystemToolForODGroovingAndOrCutoff(Dictionary<string, Object> data) //15.端面切槽工具系统
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
            //作图
            //参数
            string path = Convert.ToString(data["path"]);
            double slf = Convert.ToDouble(data["lf"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0)
            {
                if (slf < 33.5)
                {
                    scale = 4.0;
                }
                else if (slf < 45)
                {
                    scale = 3.0;
                }
                else if (slf < 67)
                {
                    scale = 2.0;
                }
                else if (slf < 89)
                {
                    scale = 1.5;
                }
                else if (slf < 134)
                {
                    scale = 1.0;
                }
                else if (slf < 179)
                {
                    scale = 0.75;
                }
                else
                {
                    scale = 0.5;
                }
            }
            double pi = Math.PI;
            double lf = Convert.ToDouble(data["lf"]) * scale;
            double bdred = Convert.ToDouble(data["bdred"]) * scale;
            double lh = Convert.ToDouble(data["lh"]) * scale;
            double dcon = Convert.ToDouble(data["dcon"]) * scale;
            double ldred = Convert.ToDouble(data["ldred"]) * scale;
            double wf = Convert.ToDouble(data["wf"]) * scale;
            double cwn = Convert.ToDouble(data["cwn"]) * scale;
            double ecd = Convert.ToDouble(data["ecd"]) * scale;
            double eca = Convert.ToDouble(data["eca"]) * pi / 180;
            double hea = Convert.ToDouble(data["hea"]) * pi / 180;
            double kapr = Convert.ToDouble(data["kapr"]) * pi / 180;
            double cwx = Convert.ToDouble(data["cwx"]) * scale;
            double cdx = Convert.ToDouble(data["cdx"]) * scale;
            double isframe = Convert.ToDouble(data["isframe"]);
            //坐标
            //主视图
            Vector2 v4 = new Vector2(dcon / 2, 0);
            Vector2 v5 = new Vector2(v4.X, -lf + ldred);
            Vector2 v6 = new Vector2(bdred / 2, v5.Y);
            Vector2 v7 = new Vector2(v6.X, -lf + lh);
            Vector2 v11 = new Vector2(wf+cwx/2, -lf);
            Vector2 v10 = new Vector2(wf+cwn/2, v11.Y + cdx);
            Vector2 v9 = new Vector2(v11.X - cwx, v11.Y);
            Vector2 v12 = new Vector2(v10.X - cwn, v10.Y);
            Vector2 v8 = new Vector2(v10.X, v7.Y - (v10.X - v7.X) / Math.Tan(hea));
            Vector2 v13 = new Vector2(-v6.X + ecd, v10.Y);
            Vector2 v14 = new Vector2(-v6.X, v13.Y + ecd / Math.Tan(eca));
            Vector2 v15 = new Vector2(v14.X, v7.Y);
            Vector2 v16 = new Vector2(v15.X, v6.Y);
            Vector2 v17 = new Vector2(-v5.X, v5.Y);
            Vector2 v18 = new Vector2(-v4.X, v4.Y);
            Vector2 v19 = new Vector2(0, 2);
            Vector2 v20 = new Vector2(0, -lf - 2);
            Vector2 v21 = new Vector2(v14.X, v13.Y);
            Vector2 v22 = new Vector2(v8.X, v7.Y);
            Vector2 v23 = new Vector2((v12.X+v10.X)/2, v10.Y+2);
            Vector2 v24 = new Vector2((v9.X+v11.X)/2, v11.Y-2);
            //线段
            //主视图
            Vector2[] Line1 = { v4, v5 };
            fun.drawBLine(dxf, Line1, 0.3, contour);
            Vector2[] Line2 = { v6, v7 };
            fun.drawBLine(dxf, Line2, 0.3, contour);
            Vector2[] Line7 = { v7, v8 };
            fun.drawBLine(dxf, Line7, 0.3, contour);
            Vector2[] Line8 = { v8, v10 };
            fun.drawBLine(dxf, Line8, 0.3, contour);
            Vector2[] Line19 = { v9, v11 };
            fun.drawBLine(dxf, Line19, 0.3, contour);
            Vector2[] Line20 = { v10, v11 };
            fun.drawBLine(dxf, Line20, 0.3, contour);
            if (ecd != 0)
            {
                Vector2[] Line3 = { v16, v14 };
                fun.drawBLine(dxf, Line3, 0.3, contour);
                Vector2[] Line4 = { v14, v13 };
                fun.drawBLine(dxf, Line4, 0.3, contour);
                Vector2[] Line5 = { v10, v13 };
                fun.drawBLine(dxf, Line5, 0.3, contour);
            }
            if (ecd == 0)
            {
                Vector2[] Line3 = { v16, v21 };
                fun.drawBLine(dxf, Line3, 0.3, contour);
                Vector2[] Line5 = { v21, v10 };
                fun.drawBLine(dxf, Line5, 0.3, contour);
            }
            Vector2[] Line6 = { v7, v15 };
            fun.drawBLine(dxf, Line6, 0.3, contour);
            Vector2[] Line9 = { v5, v17 };
            fun.drawBLine(dxf, Line9, 0.3, contour);
            Vector2[] Line13 = { v17, v18 };
            fun.drawBLine(dxf, Line13, 0.3, contour);
            Vector2[] Line14 = { v18, v4 };
            fun.drawBLine(dxf, Line14, 0.3, contour);
            Vector2[] Line15 = { v9, v12 };
            fun.drawBLine(dxf, Line15, 0.3, contour);
            Line Line10 = new Line(new Vector2(wf,v11.Y),v11);
            Line Line11 = new Line(new Vector2(wf, v11.Y), v24);
            Vector2[] Line17 = { v19, v20 };
            fun.drawPlinetype(dxf, Line17, 0.15, centre, Linetype.Center);
            Vector2[] Line18 = { v23, v24 };
            fun.drawPlinetype(dxf, Line18, 0.15, centre, Linetype.Center);
            Line Line21 = new Line(v7, v22);
            Line21.Layer = dimensioning;
            dxf.AddEntity(Line21);
            Line Line22 = new Line(v14, v13);
            Line Line23 = new Line(v14, v21);
            Line23.Layer = dimensioning;
            dxf.AddEntity(Line23);
            Line Line24 = new Line(v7, v8);
            //标注样式
            //箭头样式
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 3.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            //文本样式
            dimensionStyle.TextHeight = 3.5;
            double offset = 10;
            //线段尺寸标注
            //尺寸1
            if (lh != 0)
            {
                LinearDimension dim1 = new LinearDimension(new Line(v15, v9), -offset*2 - (v9.X - v15.X) / 2, 270, dimensionStyle);
                dim1.UserText = "LH = " + Math.Round(lh / scale, 2);
                dxf.AddEntity(dim1);
            }
            //尺寸2
            LinearDimension dim2 = new LinearDimension(new Line(v20, v24), -offset * 2 - (v11.Y - v20.Y) / 2+2, 0, dimensionStyle);
            dim2.UserText = "WF = " + Math.Round(wf / scale, 2);
            dxf.AddEntity(dim2);
            //尺寸3
            LinearDimension dim3 = new LinearDimension(new Line(v4, v11), offset * 3 + (v11.X - v4.X) / 2, 270, dimensionStyle);
            dim3.UserText = "LPR.LF = " + Math.Round(lf / scale, 2);
            dxf.AddEntity(dim3);
            //尺寸4
            LinearDimension dim4 = new LinearDimension(new Line(v6, v11), offset*2 + (v11.X - v6.X) / 2, 270, dimensionStyle);
            dim4.UserText = "LDRED = " + Math.Round(ldred / scale, 2);
            dxf.AddEntity(dim4);
            //尺寸5
            if (ecd != 0)
            {
                LinearDimension dim5 = new LinearDimension(new Line(v13, v14), -offset - cdx - (v14.Y - v13.Y) / 2, 0, dimensionStyle);
                dim5.UserText = "ECD = " + Math.Round(ecd / scale, 2);
                dxf.AddEntity(dim5);
            }
            //尺寸6
            LinearDimension dim6 = new LinearDimension(new Line(v18, v4), offset * 2, 0, dimensionStyle);
            dim6.UserText = "DCON = Φ" + Math.Round(dcon / scale, 2);
            dxf.AddEntity(dim6);
            //尺寸7
            if ((v8.X - v7.X) != 0)
            {
                Angular2LineDimension angdim7 = new Angular2LineDimension(Line24, Line21, offset, dimensionStyle);
                angdim7.UserText = "HEA = " + Math.Round(hea / pi * 180, 2) + "°";
                dxf.AddEntity(angdim7);
            }
            //尺寸8
            LinearDimension dim8 = new LinearDimension(new Line(v16, v6), offset - v5.Y, 0, dimensionStyle);
            dim8.UserText = "BDRED = Φ" + Math.Round(bdred / scale, 2);
            dxf.AddEntity(dim8);
            //尺寸9
            LinearDimension dim9 = new LinearDimension(new Line(v12, v9), -offset - (v12.X - v9.X) / 2-v9.X+v14.X, 270, dimensionStyle);
            dim9.UserText = "CDX = " + Math.Round(cdx / scale, 2);
            dxf.AddEntity(dim9);
            //尺寸10
            if (ecd != 0)
            {
                Angular2LineDimension angdim10 = new Angular2LineDimension(Line23, Line22, offset, dimensionStyle);
                angdim10.UserText = "ECA = " + Math.Round(eca / pi * 180, 2) + "°";
                dxf.AddEntity(angdim10);
            }
            //尺寸11
            LinearDimension dim11 = new LinearDimension(new Line(v9, v11), -offset, 0, dimensionStyle);
            dim11.UserText = "CW = " + Math.Round(cwx / scale, 2);
            dxf.AddEntity(dim11);
            //尺寸12
            Angular2LineDimension angdim12 = new Angular2LineDimension(Line10, Line11, offset*2, dimensionStyle);
            angdim12.UserText = "KAPR = " + Math.Round(kapr / pi * 180, 2) + "°";
            dxf.AddEntity(angdim12);
            //图框
            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA3Y(dxf, new Vector2(-148.5, 210 - lf / 2));
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void SystemToolForIDGrooving(Dictionary<string, Object> data) //16.内切槽工具系统
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
            //作图
            //参数
            string path = Convert.ToString(data["path"]);
            double slf = Convert.ToDouble(data["lf"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0)
            {
                if (slf < 33.5)
                {
                    scale = 4.0;
                }
                else if (slf < 45)
                {
                    scale = 3.0;
                }
                else if (slf < 67)
                {
                    scale = 2.0;
                }
                else if (slf < 89)
                {
                    scale = 1.5;
                }
                else if (slf < 134)
                {
                    scale = 1.0;
                }
                else if (slf < 179)
                {
                    scale = 0.75;
                }
                else
                {
                    scale = 0.5;
                }
            }
            double pi = Math.PI;
            double lf = Convert.ToDouble(data["lf"]) * scale;
            double bdred = Convert.ToDouble(data["bdred"]) * scale;
            double lh = Convert.ToDouble(data["lh"]) * scale;
            double dcon = Convert.ToDouble(data["dcon"]) * scale;
            double ldred = Convert.ToDouble(data["ldred"]) * scale;
            double wf = Convert.ToDouble(data["wf"]) * scale;
            double cwn = Convert.ToDouble(data["cwn"]) * scale;
            double ecd = Convert.ToDouble(data["ecd"]) * scale;
            double eca = Convert.ToDouble(data["eca"]) * pi / 180;
            double hea = Convert.ToDouble(data["hea"]) * pi / 180;
            double kapr = Convert.ToDouble(data["kapr"]) * pi / 180;
            double cwx = Convert.ToDouble(data["cwx"]) * scale;
            double cdx = Convert.ToDouble(data["cdx"]) * scale;
            double lpr = lf + cwx / 2;
            double isframe = Convert.ToDouble(data["isframe"]);
            //坐标
            //主视图
            Vector2 v4 = new Vector2(dcon / 2, 0);
            Vector2 v5 = new Vector2(v4.X, -lf + ldred);
            Vector2 v6 = new Vector2(bdred / 2, v5.Y);
            Vector2 v7 = new Vector2(v6.X, -lpr + lh);
            Vector2 v11 = new Vector2(wf, -lpr);
            Vector2 v10 = new Vector2(v11.X-cdx, -lf - cwn/2);
            Vector2 v9 = new Vector2(v11.X, v11.Y+cwx);
            Vector2 v12 = new Vector2(v10.X, v10.Y+cwn);
            Vector2 v8 = new Vector2(v10.X, v7.Y - (v10.X - v7.X) / Math.Tan(hea));
            Vector2 v13 = new Vector2(-v6.X + ecd, v10.Y);
            Vector2 v14 = new Vector2(-v6.X, v13.Y + ecd / Math.Tan(eca));
            Vector2 v15 = new Vector2(v14.X, v7.Y);
            Vector2 v16 = new Vector2(v15.X, v6.Y);
            Vector2 v17 = new Vector2(-v5.X, v5.Y);
            Vector2 v18 = new Vector2(-v4.X, v4.Y);
            Vector2 v19 = new Vector2(0, 2);
            Vector2 v20 = new Vector2(0, -lpr - 2);
            Vector2 v21 = new Vector2(v14.X, v13.Y);
            Vector2 v22 = new Vector2(v8.X, v7.Y);
            Vector2 v23 = new Vector2(v10.X-2, (v12.Y + v10.Y) / 2);
            Vector2 v24 = new Vector2(v9.X+2, (v9.Y + v11.Y) / 2);
            //线段
            //主视图
            Vector2[] Line1 = { v4, v5 };
            fun.drawBLine(dxf, Line1, 0.3, contour);
            Vector2[] Line2 = { v6, v7 };
            fun.drawBLine(dxf, Line2, 0.3, contour);
            Vector2[] Line7 = { v7, v8 };
            fun.drawBLine(dxf, Line7, 0.3, contour);
            Vector2[] Line8 = { v8, v10 };
            fun.drawBLine(dxf, Line8, 0.3, contour);
            Vector2[] Line19 = { v9, v11 };
            fun.drawBLine(dxf, Line19, 0.3, contour);
            Vector2[] Line20 = { v10, v11 };
            fun.drawBLine(dxf, Line20, 0.3, contour);
            if (ecd != 0)
            {
                Vector2[] Line3 = { v16, v14 };
                fun.drawBLine(dxf, Line3, 0.3, contour);
                Vector2[] Line4 = { v14, v13 };
                fun.drawBLine(dxf, Line4, 0.3, contour);
                Vector2[] Line5 = { v10, v13 };
                fun.drawBLine(dxf, Line5, 0.3, contour);
            }
            if (ecd == 0)
            {
                Vector2[] Line3 = { v16, v21 };
                fun.drawBLine(dxf, Line3, 0.3, contour);
                Vector2[] Line5 = { v21, v10 };
                fun.drawBLine(dxf, Line5, 0.3, contour);
            }
            Vector2[] Line6 = { v7, v15 };
            fun.drawBLine(dxf, Line6, 0.3, contour);
            Vector2[] Line9 = { v5, v17 };
            fun.drawBLine(dxf, Line9, 0.3, contour);
            Vector2[] Line13 = { v17, v18 };
            fun.drawBLine(dxf, Line13, 0.3, contour);
            Vector2[] Line14 = { v18, v4 };
            fun.drawBLine(dxf, Line14, 0.3, contour);
            Vector2[] Line15 = { v9, v12 };
            fun.drawBLine(dxf, Line15, 0.3, contour);
            Line Line10 = new Line(new Vector2(wf, v24.Y), v9);
            Line Line11 = new Line(new Vector2(wf, v24.Y), v24);
            Vector2[] Line17 = { v19, v20 };
            fun.drawPlinetype(dxf, Line17, 0.15, centre, Linetype.Center);
            Vector2[] Line18 = { v23, v24 };
            fun.drawPlinetype(dxf, Line18, 0.15, centre, Linetype.Center);
            Line Line21 = new Line(v7, v22);
            Line21.Layer = dimensioning;
            dxf.AddEntity(Line21);
            Line Line22 = new Line(v14, v13);
            Line Line23 = new Line(v14, v21);
            Line23.Layer = dimensioning;
            dxf.AddEntity(Line23);
            Line Line24 = new Line(v7, v8);
            //标注样式
            //箭头样式
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 3.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            //文本样式
            dimensionStyle.TextHeight = 3.5;
            double offset = 10;
            //线段尺寸标注
            //尺寸1
            if (lh != 0)
            {
                LinearDimension dim1 = new LinearDimension(new Line(v15, v11), -offset - (v11.X - v15.X) / 2, 270, dimensionStyle);
                dim1.UserText = "LH = " + Math.Round(lh / scale, 2);
                dxf.AddEntity(dim1);
            }
            //尺寸2
            LinearDimension dim2 = new LinearDimension(new Line(v20, v11), -offset * 2 - (v11.Y - v20.Y) / 2 + 2, 0, dimensionStyle);
            dim2.UserText = "WF = " + Math.Round(wf / scale, 2);
            dxf.AddEntity(dim2);
            //尺寸3
            LinearDimension dim3 = new LinearDimension(new Line(v4, v11), offset * 3 + (v11.X - v4.X) / 2, 270, dimensionStyle);
            dim3.UserText = "LPR = " + Math.Round(lpr / scale, 2);
            dxf.AddEntity(dim3);
            //尺寸4
            LinearDimension dim4 = new LinearDimension(new Line(v16, v11), -offset * 2 - (v11.X - v16.X) / 2, 270, dimensionStyle);
            dim4.UserText = "LDRED = " + Math.Round(ldred / scale, 2);
            dxf.AddEntity(dim4);
            //尺寸5
            if (ecd != 0)
            {
                LinearDimension dim5 = new LinearDimension(new Line(v13, v14), -offset - v13.Y+v11.Y - (v14.Y - v13.Y) / 2, 0, dimensionStyle);
                dim5.UserText = "ECD = " + Math.Round(ecd / scale, 2);
                dxf.AddEntity(dim5);
            }
            //尺寸6
            LinearDimension dim6 = new LinearDimension(new Line(v18, v4), offset * 2, 0, dimensionStyle);
            dim6.UserText = "DCON = Φ" + Math.Round(dcon / scale, 2);
            dxf.AddEntity(dim6);
            //尺寸7
            if ((v8.X - v7.X) != 0)
            {
                Angular2LineDimension angdim7 = new Angular2LineDimension(Line24, Line21, offset, dimensionStyle);
                angdim7.UserText = "HEA = " + Math.Round(hea / pi * 180, 2) + "°";
                dxf.AddEntity(angdim7);
            }
            //尺寸8
            LinearDimension dim8 = new LinearDimension(new Line(v16, v6), offset - v5.Y, 0, dimensionStyle);
            dim8.UserText = "BDRED = Φ" + Math.Round(bdred / scale, 2);
            dxf.AddEntity(dim8);
            //尺寸9
            LinearDimension dim9 = new LinearDimension(new Line(v10, v11), -offset - (v10.Y - v11.Y) / 2, 0, dimensionStyle);
            dim9.UserText = "CDX = " + Math.Round(cdx / scale, 2);
            dxf.AddEntity(dim9);
            //尺寸10
            if (ecd != 0)
            {
                Angular2LineDimension angdim10 = new Angular2LineDimension(Line23, Line22, offset, dimensionStyle);
                angdim10.UserText = "ECA = " + Math.Round(eca / pi * 180, 2) + "°";
                dxf.AddEntity(angdim10);
            }
            //尺寸11
            LinearDimension dim11 = new LinearDimension(new Line(v9, v11), offset, 270, dimensionStyle);
            dim11.UserText = "CW = " + Math.Round(cwx / scale, 2);
            dxf.AddEntity(dim11);
            //尺寸12
            Angular2LineDimension angdim12 = new Angular2LineDimension(Line10, Line11, offset * 2, dimensionStyle);
            angdim12.UserText = "KAPR = " + Math.Round(kapr / pi * 180, 2) + "°";
            dxf.AddEntity(angdim12);
            //尺寸13
            LinearDimension dim13 = new LinearDimension(new Line(v4, v24), offset * 2 + (v24.X - v4.X) / 2-1, 270, dimensionStyle);
            dim13.UserText = "LF = " + Math.Round(lf / scale, 2);
            dxf.AddEntity(dim13);
            //图框
            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA3Y(dxf, new Vector2(-148.5, 210 - lf / 2));
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void PullBackSystemTool(Dictionary<string, Object> data)  //17.背镗工具系统
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
            //作图
            //参数
            string path = Convert.ToString(data["path"]);
            double slpr = Convert.ToDouble(data["lpr"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0)
            {
                if (slpr < 33.5)
                {
                    scale = 4.0;
                }
                else if (slpr < 45)
                {
                    scale = 3.0;
                }
                else if (slpr < 67)
                {
                    scale = 2.0;
                }
                else if (slpr < 89)
                {
                    scale = 1.5;
                }
                else if (slpr < 134)
                {
                    scale = 1.0;
                }
                else if (slpr < 179)
                {
                    scale = 0.75;
                }
                else
                {
                    scale = 0.5;
                }
            }
            double pi = Math.PI;
            double lpr = Convert.ToDouble(data["lpr"]) * scale;
            double lf = Convert.ToDouble(data["lf"]) * scale;
            double lh = Convert.ToDouble(data["lh"]) * scale;
            double dcon = Convert.ToDouble(data["dcon"]) * scale;
            double bdred = Convert.ToDouble(data["bdred"]) * scale;
            double ldred = Convert.ToDouble(data["ldred"]) * scale;
            double wf = Convert.ToDouble(data["wf"]) * scale;
            double ic = Convert.ToDouble(data["ic"]) * scale;
            double ecd = Convert.ToDouble(data["ecd"]) * scale;
            double kapr = Convert.ToDouble(data["kapr"]) * pi / 180;
            double eca = Convert.ToDouble(data["eca"]) * pi / 180;
            double epsr = Convert.ToDouble(data["epsr"]) * pi / 180;
            double hea = Convert.ToDouble(data["hea"]) * pi / 180;
            double kn0001 = Convert.ToDouble(data["kn0001"]) * scale;
            double kn0002 = Convert.ToDouble(data["kn0002"]) * scale;
            double isframe = Convert.ToDouble(data["isframe"]);
            //坐标
            //主视图
            double l = ic / 2 / Math.Cos(epsr / 2) / Math.Sin(epsr / 2);
            Vector2 v1 = new Vector2(-dcon / 2, 0);
            Vector2 v2 = new Vector2(-v1.X, v1.Y);
            Vector2 v3 = new Vector2(wf, -lf);
            Vector2 v4 = new Vector2(v3.X - l * Math.Cos(kapr - pi / 2), v3.Y - l * Math.Sin(kapr - pi / 2));
            Vector2 v5 = new Vector2(-bdred / 2, -lpr + ecd / Math.Tan(eca));
            Vector2 v6 = new Vector2(v5.X + ecd, -lpr);
            Vector2 v15 = new Vector2(v3.X - l * Math.Sin(pi - kapr - epsr), v3.Y - l * Math.Cos(pi - kapr - epsr));
            Vector2 v10 = new Vector2(v15.X - l * Math.Cos(kapr - pi / 2), v15.Y - l * Math.Sin(kapr - pi / 2));
            Vector2 v16 = new Vector2(v15.X - kn0002 / Math.Sin(epsr) * Math.Cos(kapr - pi / 2), v15.Y - kn0002 / Math.Sin(epsr) * Math.Sin(kapr - pi / 2));
            Vector2 v7 = new Vector2(v16.X - (v16.Y + lpr) * Math.Tan(pi - kapr - epsr), v6.Y);
            Vector2 v12 = new Vector2(v1.X, -lf + ldred);
            Vector2 v13 = new Vector2(-v12.X, v12.Y);
            Vector2 v14 = new Vector2(bdred/2, v13.Y);
            Vector2 v17 = new Vector2(-v14.X, v14.Y);
            Vector2 v18 = new Vector2(v5.X, v6.Y);
            Vector2 v19 = new Vector2(v3.X, v3.Y + v3.X - v4.X);
            Vector2 v20 = new Vector2(0, 2);
            Vector2 v21 = new Vector2(0, -lpr - 2);
            Vector2 v8 = new Vector2(v14.X, -lpr + lh);
            Vector2 v9 = new Vector2(v4.X, v8.Y-(v4.X-v8.X)*Math.Tan(hea));
            Vector2 v11 = new Vector2(v5.X, v8.Y);
            //线段
            //主视图
            Vector2[] Line1 = { v1, v2 };
            fun.drawBLine(dxf, Line1, 0.3, contour);
            Vector2[] Line2 = { v2, v13 };
            fun.drawBLine(dxf, Line2, 0.3, contour);
            Vector2[] Line19 = { v13, v12 };
            fun.drawBLine(dxf, Line19, 0.3, contour);
            Vector2[] Line20 = { v14, v8 };
            fun.drawBLine(dxf, Line20, 0.3, contour);
            if (ecd != 0)
            {
                Vector2[] Line3 = { v17, v5 };
                fun.drawBLine(dxf, Line3, 0.3, contour);
                Vector2[] Line4 = { v5, v6 };
                fun.drawBLine(dxf, Line4, 0.3, contour);
                Vector2[] Line5 = { v6, v7 };
                fun.drawBLine(dxf, Line5, 0.3, contour);
            }
            if (ecd == 0)
            {
                Vector2[] Line3 = { v17, v18 };
                fun.drawBLine(dxf, Line3, 0.3, contour);
                Vector2[] Line5 = { v18, v7 };
                fun.drawBLine(dxf, Line5, 0.3, contour);
            }
            Vector2[] Line6 = { v8, v9 };
            fun.drawBLine(dxf, Line6, 0.3, contour);
            Vector2[] Line9 = { v3, v4 };
            fun.drawBLine(dxf, Line9, 0.3, contour);
            Vector2[] Line7 = { v12, v1 };
            fun.drawBLine(dxf, Line7, 0.3, contour);
            Vector2[] Line8 = { v8, v11 };
            fun.drawBLine(dxf, Line8, 0.3, contour);
            Vector2[] Line10 = { v9, v4 };
            fun.drawBLine(dxf, Line10, 0.3, contour);
            Vector2[] Line11 = { v3, v15 };
            fun.drawBLine(dxf, Line11, 0.3, contour);
            Vector2[] Line12 = { v15, v10 };
            fun.drawBLine(dxf, Line12, 0.3, contour);
            Vector2[] Line13 = { v10, v4 };
            fun.drawBLine(dxf, Line13, 0.3, contour);
            Vector2[] Line21 = { v16, v7 };
            fun.drawBLine(dxf, Line21, 0.3, contour);
            Line Line14 = new Line(v5, v18);
            Line Line15 = new Line(v3, v19);
            Line Line16 = new Line(v5, v6);
            Line Line17 = new Line(v3, v4);
            Line Line22 = new Line(v8, v9);
            Line Line24 = new Line(v8, new Vector2(v9.X,v8.Y));
            Line14.Layer = dimensioning;
            Line15.Layer = dimensioning;
            Line24.Layer = dimensioning;
            dxf.AddEntity(Line24);
            dxf.AddEntity(Line14);
            dxf.AddEntity(Line15);
            Line Line23 = new Line(v3, v15);
            Vector2[] Line18 = { v21, v20 };
            fun.drawPlinetype(dxf, Line18, 0.15, centre, Linetype.Center);
            //标注样式
            //箭头样式
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 3.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            //文本样式
            dimensionStyle.TextHeight = 3.5;
            double offset = 10;
            //线段尺寸标注
            //尺寸1
            if (lh != 0)
            {
                LinearDimension dim1 = new LinearDimension(new Line(v11, v7), -offset - (v7.X - v11.X) / 2, 270, dimensionStyle);
                dim1.UserText = "LH = " + Math.Round(lh / scale, 2);
                dxf.AddEntity(dim1);
            }
            //尺寸2
            LinearDimension dim2 = new LinearDimension(new Line(v21, v3), -offset - (v3.Y - v21.Y) / 2, 0, dimensionStyle);
            dim2.UserText = "WF = " + Math.Round(wf / scale, 2);
            dxf.AddEntity(dim2);
            //尺寸3
            LinearDimension dim3 = new LinearDimension(new Line(v1, v7), -offset * 2 - (v7.X - v1.X) / 2, 270, dimensionStyle);
            dim3.UserText = "LPR = " + Math.Round(lpr / scale, 2);
            dxf.AddEntity(dim3);
            //尺寸4
            LinearDimension dim4 = new LinearDimension(new Line(v13, v3), offset + (v3.X - v13.X) / 2, 270, dimensionStyle);
            dim4.UserText = "LDRED = " + Math.Round(ldred / scale, 2);
            dxf.AddEntity(dim4);
            //尺寸5
            if (ecd != 0)
            {
                LinearDimension dim5 = new LinearDimension(new Line(v5, v6), -offset - (v5.Y - v6.Y) / 2-2, 0, dimensionStyle);
                dim5.UserText = "ECD = " + Math.Round(ecd / scale, 2);
                dxf.AddEntity(dim5);
            }
            //尺寸6
            LinearDimension dim6 = new LinearDimension(new Line(v1, v2), offset * 2, 0, dimensionStyle);
            dim6.UserText = "DCON = Φ" + Math.Round(dcon / scale, 2);
            dxf.AddEntity(dim6);
            //尺寸7
            if ((v8.X - v7.X) != 0)
            {
                Angular2LineDimension angdim7 = new Angular2LineDimension(Line24, Line22, offset, dimensionStyle);
                angdim7.UserText = "HEA = " + Math.Round(hea / pi * 180, 2) + "°";
                dxf.AddEntity(angdim7);
            }
            //尺寸8
            LinearDimension dim8 = new LinearDimension(new Line(v17, v14), offset - v13.Y, 0, dimensionStyle);
            dim8.UserText = "BDRED = Φ" + Math.Round(bdred / scale, 2);
            dxf.AddEntity(dim8);
            //尺寸9
            LinearDimension dim9 = new LinearDimension(new Line(v10, v15), -offset, kapr/pi*180-90, dimensionStyle);
            dim9.UserText = "L = " + Math.Round(l / scale, 2);
            dxf.AddEntity(dim9);
            //尺寸10
            if (ecd != 0)
            {
                Angular2LineDimension angdim10 = new Angular2LineDimension(Line14, Line16, offset, dimensionStyle);
                angdim10.UserText = "ECA = " + Math.Round(eca / pi * 180, 2) + "°";
                dxf.AddEntity(angdim10);
            }
            //尺寸11
            LinearDimension dim11 = new LinearDimension(new Line(v13, v3), offset+(v3.X-v13.X)/2, 270, dimensionStyle);
            dim11.UserText = "LDRED = " + Math.Round(ldred / scale, 2);
            dxf.AddEntity(dim11);
            //尺寸12
            Angular2LineDimension angdim12 = new Angular2LineDimension(Line15, Line17, offset, dimensionStyle);
            angdim12.UserText = "KAPR = " + Math.Round(kapr / pi * 180, 2) + "°";
            dxf.AddEntity(angdim12);
            //尺寸13
            LinearDimension dim13 = new LinearDimension(new Line(v2, v3), offset * 2 + (v3.X - v2.X) / 2, 270, dimensionStyle);
            dim13.UserText = "LF = " + Math.Round(lf / scale, 2);
            dxf.AddEntity(dim13);
            //尺寸14
            Angular2LineDimension angdim14 = new Angular2LineDimension(Line17, Line23, offset*2, dimensionStyle);
            angdim14.UserText = "EPSR = " + Math.Round(epsr / pi * 180, 2) + "°";
            dxf.AddEntity(angdim14);
            //图框
            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA3Y(dxf, new Vector2(-148.5, 210 - lf / 2));
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }
            fun.SetLayer(dxf);
            fun.SetByLayer(dxf);
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
        public static void SystemToolNeutralDesignForODTurning(Dictionary<string, Object> data)  //18.外圆车削中性工具系统
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
            //作图
            //参数
            string path = Convert.ToString(data["path"]);
            double slf = Convert.ToDouble(data["lf"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            if (scale == 0)
            {
                if (slf < 33.5)
                {
                    scale = 4.0;
                }
                else if (slf < 45)
                {
                    scale = 3.0;
                }
                else if (slf < 67)
                {
                    scale = 2.0;
                }
                else if (slf < 89)
                {
                    scale = 1.5;
                }
                else if (slf < 134)
                {
                    scale = 1.0;
                }
                else if (slf < 179)
                {
                    scale = 0.75;
                }
                else
                {
                    scale = 0.5;
                }
            }
            double pi = Math.PI;
            double lf = Convert.ToDouble(data["lf"]) * scale;
            double lh = Convert.ToDouble(data["lh"]) * scale;
            double dcon = Convert.ToDouble(data["dcon"]) * scale;
            double bdred = Convert.ToDouble(data["bdred"]) * scale;
            double ldred = Convert.ToDouble(data["ldred"]) * scale;
            double ic = Convert.ToDouble(data["ic"]) * scale;
            double kapr = Convert.ToDouble(data["kapr"]) * pi / 180;
            double epsr = pi - kapr * 2;
            double isframe = Convert.ToDouble(data["isframe"]);
            //坐标
            //主视图
            double l = ic / 2 / Math.Cos(epsr / 2) / Math.Sin(epsr / 2);
            Vector2 v1 = new Vector2(-dcon / 2, 0);
            Vector2 v2 = new Vector2(-v1.X, v1.Y);
            Vector2 v3 = new Vector2(v2.X, -lf+ldred);
            Vector2 v4 = new Vector2(bdred/2, v3.Y);
            Vector2 v5 = new Vector2(v4.X, -lf + v4.X * Math.Tan(kapr));
            Vector2 v6 = new Vector2(0, -lf);
            Vector2 v7 = new Vector2(-v5.X, v5.Y);
            Vector2 v8 = new Vector2(-v4.X, v4.Y);
            Vector2 v9 = new Vector2(-v3.X, v3.Y);
            Vector2 v12 = new Vector2(l * Math.Sin(epsr/2), v6.Y+ l * Math.Cos(epsr / 2));
            Vector2 v13 = new Vector2(v6.X, v6.Y + l * 2 * Math.Cos(epsr / 2));
            Vector2 v14 = new Vector2(-v12.X, v12.Y);
            Vector2 v16 = new Vector2(0, 2);
            Vector2 v15 = new Vector2(0, -lf - 2);
            double a = v8.X;
            double b = v4.X;
            if ((v5.Y - v6.Y - lh) > 0)
            {
                b = lh * Math.Tan(epsr / 2);
                a = -lh * Math.Tan(epsr / 2);
            }
            Vector2 v10 = new Vector2(a, -lf + lh);
            Vector2 v11 = new Vector2(b, -lf + lh);
            //线段
            //主视图
            Vector2[] Line1 = { v1, v2 };
            fun.drawBLine(dxf, Line1, 0.3, contour);
            Vector2[] Line2 = { v2, v3 };
            fun.drawBLine(dxf, Line2, 0.3, contour);
            Vector2[] Line19 = { v3, v9 };
            fun.drawBLine(dxf, Line19, 0.3, contour);
            Vector2[] Line20 = { v9, v1 };
            fun.drawBLine(dxf, Line20, 0.3, contour);
            Vector2[] Line3 = { v4, v5 };
                fun.drawBLine(dxf, Line3, 0.3, contour);
                Vector2[] Line4 = { v5, v6 };
                fun.drawBLine(dxf, Line4, 0.3, contour);
                Vector2[] Line5 = { v6, v7 };
                fun.drawBLine(dxf, Line5, 0.3, contour);
            Vector2[] Line6 = { v7, v8 };
            fun.drawBLine(dxf, Line6, 0.3, contour);
            Vector2[] Line9 = { v10, v11 };
            fun.drawBLine(dxf, Line9, 0.3, contour);
            Vector2[] Line7 = { v12, v13 };
            fun.drawBLine(dxf, Line7, 0.3, contour);
            Vector2[] Line8 = { v13, v14 };
            fun.drawBLine(dxf, Line8, 0.3, contour);
            Line Line14 = new Line(v6, new Vector2(v5.X,v6.Y));
            Line Line15 = new Line(v6, v5);
            Line Line16 = new Line(v6, v7);
            Line14.Layer = dimensioning;
            dxf.AddEntity(Line14);
            Vector2[] Line18 = { v15, v16 };
            fun.drawPlinetype(dxf, Line18, 0.15, centre, Linetype.Center);
            //标注样式
            //箭头样式
            DimensionStyle dimensionStyle = fun.CreateDimStyle();
            dimensionStyle.ArrowSize = 3.5;
            dimensionStyle.DimArrow1 = DimensionArrowhead.Closedfilled;
            dimensionStyle.DimArrow2 = DimensionArrowhead.Closedfilled;
            //文本样式
            dimensionStyle.TextHeight = 3.5;
            double offset = 10;
            //线段尺寸标注
            //尺寸1
            if (lh != 0)
            {
                LinearDimension dim1 = new LinearDimension(new Line(v10, v6), -offset + v10.X / 2, 270, dimensionStyle);
                dim1.UserText = "LH = " + Math.Round(lh / scale, 2);
                dxf.AddEntity(dim1);
            }
            //尺寸4
            LinearDimension dim4 = new LinearDimension(new Line(v8, v6), -offset*2 + v8.X / 2, 270, dimensionStyle);
            dim4.UserText = "LDRED = " + Math.Round(ldred / scale, 2);
            dxf.AddEntity(dim4);
            //尺寸6
            LinearDimension dim6 = new LinearDimension(new Line(v1, v2), offset * 2, 0, dimensionStyle);
            dim6.UserText = "DCON = Φ" + Math.Round(dcon / scale, 2);
            dxf.AddEntity(dim6);
            //尺寸8
            LinearDimension dim8 = new LinearDimension(new Line(v8, v4), offset - v3.Y, 0, dimensionStyle);
            dim8.UserText = "BDRED = Φ" + Math.Round(bdred / scale, 2);
            dxf.AddEntity(dim8);
            //尺寸9
            LinearDimension dim9 = new LinearDimension(new Line(v6, v12), -offset, kapr / pi * 180, dimensionStyle);
            dim9.UserText = "L = " + Math.Round(l / scale, 2);
            dxf.AddEntity(dim9);
            //尺寸12
            Angular2LineDimension angdim12 = new Angular2LineDimension(Line14, Line15, offset*3, dimensionStyle);
            angdim12.UserText = "KAPR = " + Math.Round(kapr / pi * 180, 2) + "°";
            dxf.AddEntity(angdim12);
            //尺寸13
            LinearDimension dim13 = new LinearDimension(new Line(v2, v6), offset * 2 + v2.X / 2, 270, dimensionStyle);
            dim13.UserText = "LF = " + Math.Round(lf / scale, 2);
            dxf.AddEntity(dim13);
            //尺寸14
            Angular2LineDimension angdim14 = new Angular2LineDimension(Line15, Line16, offset, dimensionStyle);
            angdim14.UserText = "EPSR = " + Math.Round(epsr / pi * 180, 2) + "°";
            dxf.AddEntity(angdim14);
            //图框
            if (isframe == 1)
            {
                Dictionary<string, Vector2> position = Frame.frameA3Y(dxf, new Vector2(-148.5, 210 - lf / 2));
                fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
            }
            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
    }
}
